Ok, I must be having a brainfart because I'm almost certain I've done this before in a fairly similar way, but I cannot get it to work now.
Here's the situation:
I have a survey form that has some required fields that I verify are filled in onSubmit. I'm trying to use one script function to check and make sure that a selection is chosen from the the radio selections. Unfortunately it doesn't work, and I'm sure it's because I'm sending or calling a variable incorrectly, but I can't find a way to test it out & see what the variable's value is.
Here's my code:
function validate() {
var errormessage = new String();
if(isEmpty(document.survey.why_rating.value))
{ errormessage += "\n\n Please enter why you rated the website the way you did."; }
if(Checker("survey.current_rating.checked"))
{ errormessage += "\n\n Please rate the current website."; }
if(Checker("survey.visit.checked"))
{ errormessage += "\n\n Please tell us how often you visit the website currently."; }
if(Checker("survey.age.checked"))
{ errormessage += "\n\n Please tell us your age range."; }
if(Checker("survey.marital.checked"))
{ errormessage += "\n\n Please tell us your marital status."; }
if(Checker("survey.gender.checked"))
{ errormessage += "\n\n Please select a gender."; }
if(Checker("survey.internet.checked"))
{ errormessage += "\n\n Please tell us your primary internet connection type"; }
if(errormessage.length > 2) {
alert('NOTE:' + errormessage);
return false;
}
return true;
}
function isEmpty(ss) {
if(ss.length > 0) {
return false; }
return true;
}
function Checker(q) {
var ret=true;
for(i=0; i > 5; i++)
{
if (q)
{
ret=false;
}
}
return ret;
}
Here's some of the form:
<script src="*edit*/survey/survey2.js">
</script>
<form action="*edit*/survey/surveythankyou.php" name="survey" onSubmit="return validate();">
<b>Your Name: </b>
(optional)<br />
<input type="text" name="dept" size="50" maxlength="255"/>
<br />
<b>E-mail Address:</b>(optional)
<br />
<input type="text" name="name" size="50" maxlength="255"/>
<br />
<br />
<b>How old are you?</b><font color="red">*</font>
<br />
<br />
<table border="1" bordercolor="#CCCCCC"><tr align="center"><td>12 and under</td><td>13-17</td><td>18-25</td><td>26-39</td><td>40-59</td><td>60 and over</td></tr><tr align="center"><td>
<input type="radio" name="age" id="age" value="1"/></td><td><input type="radio" name="age" id="age" value="2"/></td><td><input type="radio" name="age" id="age" value="3"/></td><td><input type="radio" name="age" id="age" value="4"/></td><td><input type="radio" name="age" id="age" value="5"/></td><td><input type="radio" name="age" id="age" value="6"/></td></tr></table>
<br />
<br />
<b>Gender?</b><font color="red">*</font>
<table border="1" bordercolor="#CCCCCC"><tr align="center"><td>Male</td><td>Female</td></tr><tr align="center"><td>
<input type="radio" name="gender" id="gender" value="M"/></td><td><input type="radio" name="gender" id="gender" value="F"/></td></tr></table>
<br />
<br />
<b>Are you married or single?</b><font color="red">*</font>
<table border="1" bordercolor="#CCCCCC"><tr align="center"><td>Single</td><td>Married</td></tr><tr align="center"><td>
<input type="radio" name="marital" id="marital" value="Single"/></td><td><input type="radio" name="marital" id="marital" value="Married"/></td></tr></table>
<br />
<br />
<b>What type of internet connection do you use?</b><font color="red">*</font>
<table border="1" bordercolor="#CCCCCC"><tr align="center"><td>Broadband</td><td>Dial-up</td></tr><tr align="center"><td>
<input type="radio" name="internet" id="internet" value="B"/></td><td><input type="radio" name="internet" id="internet" value="D"/></td></tr></table>
<br />
<br />
<b>How often do you visit the website currently? (Please choose what closest describes you):</b><font color="red">*</font><br /><br />
<table border="1" bordercolor="#CCCCCC"><tr align="center"><td>This is my first time here</td><td>Once a year</td><td>Once a month</td><td>Once a week</td><td>At least once a day</td></tr><tr align="center"><td>
<input type="radio" name="visit" id="visit" value="1"/></td><td><input type="radio" name="visit" id="visit" value="2"/></td><td><input type="radio" name="visit" id="visit" value="3"/></td><td><input type="radio" name="visit" id="visit" value="4"/></td><td><input type="radio" name="visit" id="visit" value="5"/></td></tr></table><br /><br />
<b>How would you rate the current website overall (appearance, functionality, ease of use, etc?):</b><font color="red">*</font><br /><br />
<table border="1" bordercolor="#CCCCCC"><tr align="center"><td>We'd be better off with nothing</td><td>Better than nothing</td><td>Adequate</td><td>Pretty Good</td><td>One of the best you've ever seen</td></tr><tr align="center"><td>
<input type="radio" name="current_rating" value="1"/></td><td><input type="radio" name="current_rating" id="current_rating" value="2"/></td><td><input type="radio" name="current_rating" id="current_rating" value="3"/></td><td><input type="radio" name="current_rating" id="current_rating" value="4"/></td><td><input type="radio" name="current_rating" id="current_rating" value="5"/></td></tr></table><br />
<b>Why:</b><font color="red">*</font> <br />
<textarea name="why_rating" rows="5" cols="50"></textarea>
<br />
I don't know what stupid thing I'm doing, or not doing, but it is frustrating me.
The deal is, I could easily get this done via php, but I ALWAYS like to know what I'm doing incorrectly. I tend to learn best that way.
Thanks in advance to anyone that can help me out.
Here's the situation:
I have a survey form that has some required fields that I verify are filled in onSubmit. I'm trying to use one script function to check and make sure that a selection is chosen from the the radio selections. Unfortunately it doesn't work, and I'm sure it's because I'm sending or calling a variable incorrectly, but I can't find a way to test it out & see what the variable's value is.
Here's my code:
function validate() {
var errormessage = new String();
if(isEmpty(document.survey.why_rating.value))
{ errormessage += "\n\n Please enter why you rated the website the way you did."; }
if(Checker("survey.current_rating.checked"))
{ errormessage += "\n\n Please rate the current website."; }
if(Checker("survey.visit.checked"))
{ errormessage += "\n\n Please tell us how often you visit the website currently."; }
if(Checker("survey.age.checked"))
{ errormessage += "\n\n Please tell us your age range."; }
if(Checker("survey.marital.checked"))
{ errormessage += "\n\n Please tell us your marital status."; }
if(Checker("survey.gender.checked"))
{ errormessage += "\n\n Please select a gender."; }
if(Checker("survey.internet.checked"))
{ errormessage += "\n\n Please tell us your primary internet connection type"; }
if(errormessage.length > 2) {
alert('NOTE:' + errormessage);
return false;
}
return true;
}
function isEmpty(ss) {
if(ss.length > 0) {
return false; }
return true;
}
function Checker(q) {
var ret=true;
for(i=0; i > 5; i++)
{
if (q)
{
ret=false;
}
}
return ret;
}
Here's some of the form:
<script src="*edit*/survey/survey2.js">
</script>
<form action="*edit*/survey/surveythankyou.php" name="survey" onSubmit="return validate();">
<b>Your Name: </b>
(optional)<br />
<input type="text" name="dept" size="50" maxlength="255"/>
<br />
<b>E-mail Address:</b>(optional)
<br />
<input type="text" name="name" size="50" maxlength="255"/>
<br />
<br />
<b>How old are you?</b><font color="red">*</font>
<br />
<br />
<table border="1" bordercolor="#CCCCCC"><tr align="center"><td>12 and under</td><td>13-17</td><td>18-25</td><td>26-39</td><td>40-59</td><td>60 and over</td></tr><tr align="center"><td>
<input type="radio" name="age" id="age" value="1"/></td><td><input type="radio" name="age" id="age" value="2"/></td><td><input type="radio" name="age" id="age" value="3"/></td><td><input type="radio" name="age" id="age" value="4"/></td><td><input type="radio" name="age" id="age" value="5"/></td><td><input type="radio" name="age" id="age" value="6"/></td></tr></table>
<br />
<br />
<b>Gender?</b><font color="red">*</font>
<table border="1" bordercolor="#CCCCCC"><tr align="center"><td>Male</td><td>Female</td></tr><tr align="center"><td>
<input type="radio" name="gender" id="gender" value="M"/></td><td><input type="radio" name="gender" id="gender" value="F"/></td></tr></table>
<br />
<br />
<b>Are you married or single?</b><font color="red">*</font>
<table border="1" bordercolor="#CCCCCC"><tr align="center"><td>Single</td><td>Married</td></tr><tr align="center"><td>
<input type="radio" name="marital" id="marital" value="Single"/></td><td><input type="radio" name="marital" id="marital" value="Married"/></td></tr></table>
<br />
<br />
<b>What type of internet connection do you use?</b><font color="red">*</font>
<table border="1" bordercolor="#CCCCCC"><tr align="center"><td>Broadband</td><td>Dial-up</td></tr><tr align="center"><td>
<input type="radio" name="internet" id="internet" value="B"/></td><td><input type="radio" name="internet" id="internet" value="D"/></td></tr></table>
<br />
<br />
<b>How often do you visit the website currently? (Please choose what closest describes you):</b><font color="red">*</font><br /><br />
<table border="1" bordercolor="#CCCCCC"><tr align="center"><td>This is my first time here</td><td>Once a year</td><td>Once a month</td><td>Once a week</td><td>At least once a day</td></tr><tr align="center"><td>
<input type="radio" name="visit" id="visit" value="1"/></td><td><input type="radio" name="visit" id="visit" value="2"/></td><td><input type="radio" name="visit" id="visit" value="3"/></td><td><input type="radio" name="visit" id="visit" value="4"/></td><td><input type="radio" name="visit" id="visit" value="5"/></td></tr></table><br /><br />
<b>How would you rate the current website overall (appearance, functionality, ease of use, etc?):</b><font color="red">*</font><br /><br />
<table border="1" bordercolor="#CCCCCC"><tr align="center"><td>We'd be better off with nothing</td><td>Better than nothing</td><td>Adequate</td><td>Pretty Good</td><td>One of the best you've ever seen</td></tr><tr align="center"><td>
<input type="radio" name="current_rating" value="1"/></td><td><input type="radio" name="current_rating" id="current_rating" value="2"/></td><td><input type="radio" name="current_rating" id="current_rating" value="3"/></td><td><input type="radio" name="current_rating" id="current_rating" value="4"/></td><td><input type="radio" name="current_rating" id="current_rating" value="5"/></td></tr></table><br />
<b>Why:</b><font color="red">*</font> <br />
<textarea name="why_rating" rows="5" cols="50"></textarea>
<br />
I don't know what stupid thing I'm doing, or not doing, but it is frustrating me.
The deal is, I could easily get this done via php, but I ALWAYS like to know what I'm doing incorrectly. I tend to learn best that way.
Thanks in advance to anyone that can help me out.