jb77
10-26-2006, 05:16 PM
Can anybody help me (a javascript newbie) figure out why this script validation isn't working? :confused: I'm tearing my hair out with this... any help is appreciated!!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>Survey</TITLE>
<script type="text/javascript" language="JavaScript">
<!--
function CheckRequiredFields() {
var errormessage = new String();
if(validate(document.Survey.x_Hobbies))
{ errormessage += "\n\nPlease answer what your \"other\" hobbies are (question #3)."; }
if(errormessage.length > 2) {
alert('NOTE:' + errormessage);
return false;
}
return true;
}
function validate(ss) {
if ((ss.Other==true)&&(document.Survey.x_Hobbies_Other.value.length==0)) { return true; }
return false;
}
//-->
</script>
<link rel="StyleSheet" type="text/css" href="store.css" media="screen">
</HEAD>
<BODY>
<table width="100%" cellpadding="20" cellspacing="0" bgcolor="#FFFFFF" border="0">
<tr>
<td>
<h1 class="survey">Survey</h1>
<form action="/cgi-bin/MasterFeedback.cgi" method="post" name="Survey" onSubmit="return CheckRequiredFields()">
<input type="hidden" name="subject" value="Shopping Survey-0610">
<input type="hidden" name="realname" value="john">
<input type="hidden" name="email" value="john@doe.com">
<input type="hidden" name="thankyou" value="/cgi-bin/survey0610_confirm.cgi">
<ol class="questions">
<li>What are your favorite hobbies? <span class="note">(choose all that apply)</span>
<ul class="cols">
<li><input type="checkbox" name="x_Hobbies" value="Music" /> Music</li>
<li><input type="checkbox" name="x_Hobbies" value="Sports" /> Sports</li>
<li><input type="checkbox" name="x_Hobbies" value="ArtsCrafts" /> Arts / Crafts</li>
<li><input type="checkbox" name="x_Hobbies" value="Reading" /> Reading</li>
<li><input type="checkbox" name="x_Hobbies" value="TV" /> Watching TV</li>
<li><input type="checkbox" name="x_Hobbies" value="Cooking" /> Cooking</li>
<li><input type="checkbox" name="x_Hobbies" value="HomeDecorating" /> Home Decorating</li>
<li><input type="checkbox" name="x_Hobbies" value="Fashion" /> Fashion</li>
<li><input type="checkbox" name="x_Hobbies" value="Shopping" /> Shopping</li>
<li class="widecol"><input type="checkbox" name="x_Hobbies" value="Other" /> Other: <input type="text" name="x_Hobbies_Other" size="40" maxlength="" onfocus="this.className='currentField'" onchange="this.className='changedField'" /></li>
</ul>
</li>
</ol>
<p>Thank you for filling out the survey. Please click SUBMIT!</p>
<p class="center"><input type="image" src="images/2006/btn_submit_wht.gif" name="submitbutton" alt="Submit" /><input type="reset" value="Clear Form" class="resetbtn" alt="Clear All Form Fields" onclick="if (!confirm('Are you sure you want to clear this form?')) return false;" /></p><br />
</form>
</td>
</tr>
</table>
</BODY>
</HTML>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>Survey</TITLE>
<script type="text/javascript" language="JavaScript">
<!--
function CheckRequiredFields() {
var errormessage = new String();
if(validate(document.Survey.x_Hobbies))
{ errormessage += "\n\nPlease answer what your \"other\" hobbies are (question #3)."; }
if(errormessage.length > 2) {
alert('NOTE:' + errormessage);
return false;
}
return true;
}
function validate(ss) {
if ((ss.Other==true)&&(document.Survey.x_Hobbies_Other.value.length==0)) { return true; }
return false;
}
//-->
</script>
<link rel="StyleSheet" type="text/css" href="store.css" media="screen">
</HEAD>
<BODY>
<table width="100%" cellpadding="20" cellspacing="0" bgcolor="#FFFFFF" border="0">
<tr>
<td>
<h1 class="survey">Survey</h1>
<form action="/cgi-bin/MasterFeedback.cgi" method="post" name="Survey" onSubmit="return CheckRequiredFields()">
<input type="hidden" name="subject" value="Shopping Survey-0610">
<input type="hidden" name="realname" value="john">
<input type="hidden" name="email" value="john@doe.com">
<input type="hidden" name="thankyou" value="/cgi-bin/survey0610_confirm.cgi">
<ol class="questions">
<li>What are your favorite hobbies? <span class="note">(choose all that apply)</span>
<ul class="cols">
<li><input type="checkbox" name="x_Hobbies" value="Music" /> Music</li>
<li><input type="checkbox" name="x_Hobbies" value="Sports" /> Sports</li>
<li><input type="checkbox" name="x_Hobbies" value="ArtsCrafts" /> Arts / Crafts</li>
<li><input type="checkbox" name="x_Hobbies" value="Reading" /> Reading</li>
<li><input type="checkbox" name="x_Hobbies" value="TV" /> Watching TV</li>
<li><input type="checkbox" name="x_Hobbies" value="Cooking" /> Cooking</li>
<li><input type="checkbox" name="x_Hobbies" value="HomeDecorating" /> Home Decorating</li>
<li><input type="checkbox" name="x_Hobbies" value="Fashion" /> Fashion</li>
<li><input type="checkbox" name="x_Hobbies" value="Shopping" /> Shopping</li>
<li class="widecol"><input type="checkbox" name="x_Hobbies" value="Other" /> Other: <input type="text" name="x_Hobbies_Other" size="40" maxlength="" onfocus="this.className='currentField'" onchange="this.className='changedField'" /></li>
</ul>
</li>
</ol>
<p>Thank you for filling out the survey. Please click SUBMIT!</p>
<p class="center"><input type="image" src="images/2006/btn_submit_wht.gif" name="submitbutton" alt="Submit" /><input type="reset" value="Clear Form" class="resetbtn" alt="Clear All Form Fields" onclick="if (!confirm('Are you sure you want to clear this form?')) return false;" /></p><br />
</form>
</td>
</tr>
</table>
</BODY>
</HTML>