Mulith
asked on
Javascript client side validation problem.
Hi all,
Having a bit of a problem with my client side validation. I use 2 different forms depending on the user type. My client side validation works fine for one of the forms but the other is not validating the last two fields.
Here is how I serve up the form:
and this is my validation:
When the extended form is displayed the validation works but if the normal form is displayed it skips the validation for "security_code" and "Note". So for some reason when "extended" is not = 1 then the two fields below the that "if" statement block of code is ignored.
Any suggestions?
Having a bit of a problem with my client side validation. I use 2 different forms depending on the user type. My client side validation works fine for one of the forms but the other is not validating the last two fields.
Here is how I serve up the form:
<form name="contactus" id="contactus" action="<? echo $_SERVER["REQUEST_URI"]; ?>" method="post" enctype="multipart/form-data" onsubmit="return OnSubmit(contactus);">
<fieldset style=" -moz-border-radius: 8px; border-radius: px;">
<legend style="font-size:18px; vertical-align:top; color:#FC9200;">Contact this seller</legend>
<table width= "100%" cellpadding="5px">
<tr>
<td style="border-bottom:dotted #CCC 2px">
<table width="40%" cellspacing="2" cellpadding="0" >
<tr>
<td align="left">Title: <br /><?=$rs->SelectSQLWithValue("title", "form", "SELECT title, title, id FROM title WHERE title != '' ORDER BY id", 60, "",$title)?></td>
<td align="left">First Name: <br /><?=$rs->InputTextWithValue("first_name", "form", 100, 150,$f_name)?></td>
<td align="left">Last Name: <br /><?=$rs->InputTextWithValue("last_name", "form", 100, 150,$l_name)?></td>
<td></td>
</tr>
<tr >
<td align="left" colspan="4">Your Email Address:<br /><?=$rs->InputTextWithValue("email", "form", 100, 300,$email)?></td>
</tr>
<tr>
<td align="left" colspan="4">Your Contact Number: <i>(optional)</i><br /><?=$rs->InputTextWithValue("contact_number", "form", 100, 200,$contact_number)?></td>
</tr>
<?
$user = $myrow['user_id'];
$sql="SELECT user_id FROM aandc_offices WHERE user_id =".$user;
$result = mysql_query($sql);
$user_count = mysql_num_rows($result);
if($user_count > 0){
include("aandc_add.html");
?>
<input type="hidden" value="1" id="extended" name="extended"/>
<?
} else {
?>
<input type="hidden" value="0" id="extended" name="extended"/>
<? } ?>
<tr>
<td align="left" colspan="4">Country: <br /><?=$rs->SelectSQLWithValue("country", "form", "SELECT id, name, id FROM countries ORDER BY id", 200,"nodefault",$country)?></td>
</tr>
<tr>
<td height="50px" align="left"></td></tr>
<tr><td colspan="4" align="left"><? echo $alert; ?></td></tr>
<tr >
<td align="left" colspan="2" style="padding-left:1px; background-color:#E8E8E8;"><label for="security_code">Enter this security code: </label><br /><input id="security_code" name="security_code" type="text" /></td><td colspan="2" align="left"><img src="/captcha/CaptchaSecurityImages.php?width=100&height=40&characters=5" /></td></tr>
<tr><td width="15px"></td><td></td><td></td><td></td></tr>
</table>
</td>
<td style="border-left:dotted #CCC 2px; border-bottom:dotted #CCC 2px; padding-top:2px" class="top">
<table>
<tr>
<td align="left" width="60%" rowspan="6">Your message: <br /><?=$rs->InputNoteWithValue2("Note", "form", 500, 228, 14, 100,$note)?></td>
</tr>
</table>
</td>
</tr>
<tr><td colspan="2" style="color:#999; border-bottom:dotted #CCC 2px">Mysite.co.uk will not share your personal data with any other third party, unless you have given us your express permission to do so. By submitting this form, you confirm that you agree to our <a href="http://www.mysite.co.uk/Terms_and_Conditions.php" rel="nofollow,noindex">Terms & Conditions</a> and <a href="http://www.mysite.co.uk/Privacy_Policy.php" rel="nofollow,noindex">Privacy Policy</a>.</td></tr>
<tr><td class="input_label" align="center" colspan="2"><?=$rs->ButtonSubmitSendUnsecure("", "input_label")?></td></tr>
</table>
and this is my validation:
function OnSubmit(f) {
if(Blank(f.elements['title'], 'Title'))
return false;
if(Blank(f.elements['first_name'], 'First Name'))
return false;
if(Blank(f.elements['last_name'], 'Last Name'))
return false;
if(Blank(f.elements['email'], 'Email'))
return false;
if(f.elements['extended'] = 1) {
if(Blank(f.elements['address1'], 'Address 1'))
return false;
if(Blank(f.elements['city'], 'City/Town'))
return false;
if(f.elements['county'].value == "0"){
alert("This seller requires you to enter a County value before proceeding.");
return false;
}
if(Blank(f.elements['postcode'], 'Postcode/Zip'))
return false;
}
if(Blank(f.elements['security_code'], 'Security Code'))
return false;
if(Blank(f.elements['Note'], 'Your Message'))
return false;
return true;
}
When the extended form is displayed the validation works but if the normal form is displayed it skips the validation for "security_code" and "Note". So for some reason when "extended" is not = 1 then the two fields below the that "if" statement block of code is ignored.
Any suggestions?
ASKER
Yes when I do that then the extended versions does not work properly and the normal version starts to work.
<<then the extended versions does not work properly >>
please elaborate and be specific...thanks
please elaborate and be specific...thanks
ASKER
Well this is the section that is used to differentiate the two forms:
As you can see if I find a value in the table i adds the aandc_offices.html contents which can be seen below:
Let me know if you need anything more.
<?
$user = $myrow['user_id'];
$sql="SELECT user_id FROM aandc_offices WHERE user_id =".$user;
$result = mysql_query($sql);
$user_count = mysql_num_rows($result);
if($user_count > 0){
include("aandc_add.html");
?>
<input type="hidden" value="1" id="extended" name="extended"/>
<?
} else {
?>
<input type="hidden" value="0" id="extended" name="extended"/>
<? } ?>
As you can see if I find a value in the table i adds the aandc_offices.html contents which can be seen below:
<tr >
<td align="left" colspan="4">Address1:<br /><?=$rs->InputTextWithValue("address1", "form", 100, 150,$address1)?></td>
</tr>
<tr >
<td align="left" colspan="4">Address2:<br /><?=$rs->InputTextWithValue("address2", "form", 100, 150,$address2)?></td>
</tr>
<tr >
<td align="left" colspan="4">Town/City:<br /><?=$rs->InputTextWithValue("city", "form", 100, 120,$city_enq)?></td>
</tr>
<tr><td align="left" colspan="4">County:<br /><?=$rs->SelectSQLWithValue("county", "form", "SELECT id, name, tier_value FROM locations WHERE tier_value < 5 AND tier5 = 0 AND tier_value = 4 OR(name='London') ORDER BY name", 200,'noselection',$county)?> <span style="color:#5c9514; font-size:14px">*</span></td></tr>
<tr >
<td align="left" colspan="4">Post Code/Zip:<br /><?=$rs->InputTextWithValue("postcode", "form", 9, 80,$postcode)?></td>
</tr>
Let me know if you need anything more.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Figured it out myself
if(f.elements['extended'] == 1) {