I have a small problem with JavaScript in safari and google chrome (not yet tested with firefox).
Let me explain: I'm enthusiasm to create a new website for our company and it is a party with a form. In this form I must control the content before sending. That is to say whether all fields are filled, etc. If a field is missing, I have a box dialog (function alert ()) that appears informing me to fill in empty areas.
Under IE8 it works very well, but in Chrome or Safari, when I validate the form, even as some fields or all fields are empty, it sends back a form without any data without my dialog box appears.
Does someone has an idea where the problem may be?
Here is the code form ( "envoi.inc.php" retrieves the data and transmit them by mail to an address in-house):
HTML Code:
<form action="inc/envoi.inc.php" method="post" enctype="multipart/form-data" name="formula" onsubmit="MM_validateForm('nom','','R','prename','','R','address','','R','numero','','R','cp','','R','commune','','R','telephone','','R','email','','RisEmail');return document.MM_returnValue">
Name :<br><input type="text" name="name" size=30><span class="Style25">*</span></br>
Prename :<br><input type="text" name="prename" size=30><span class="Style25">*</span></br>
Address :<br><input type="text" name="address" size=30><span class="Style25">*</span> N° : <input type="text" name="numero" size="4"><span class="Style25">*</span></br?
Code Postal :<br><input type="text" name="cp" size="4"><span class="Style25">*</span></br>
Commune :<br><input type="text" name="community" size=30><span class="Style25">*</span></br>
Tel :<br><input type="text" name="telephone" size=30><span class="Style25">*</span></br>
E-mail :<br><input type="text" name="email" size=30><span class="Style25">*</span></br>
Relates :
<SELECT name="list" size="1" class="style1">
<OPTION VALUE="0">Choose</OPTION>
<OPTION VALUE="1">A</OPTION>
<OPTION VALUE="2">Two</OPTION>
<OPTION VALUE="3">Other</OPTION>
</SELECT>< /br>
Your message :<br><textarea name="comment" rows="10" cols="50"></textarea>< /br>
<input class="style1" type="submit" name="Send" VALUE="Send">
<input class="style1" type="reset" VALUE="Clear">
</form>
here is the script of checking fields:
HTML Code:
function MM_validateForm()
{
if (document.getElementById)
{
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3)
{
test=args[i+2];
val=document.getElementById(args[i]);
if (val)
{
nm=val.name;
if ((val=val.value)!="" )
{
if (test.indexOf('isEmail')!=-1)
{
p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain a valid email address.\n';
}
else if (test!='R')
{
num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1)
{
p=test.indexOf(':');
min=test.substring(8,p);
max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
}
}
}
else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n';
}
} if (errors) alert('The following errors must be corrected:\n'+errors);
document.MM_returnValue = (errors == '');
}
}
Bookmarks