Arrgghhhh... I must have read this code 20 times. The old "2nd set of eyes" adage. Thanks.
Main Topics
Browse All TopicsI'm getting a syntax error pointing to the "function" line of the following code:
function valform() {
if (document.mySurvey.R1.chec
alert("Q1 answered");
if (document.mySurvey.R1.chec
if (document.mySurvey.R21.che
(document.mySurvey.R23.che
alert("Q2 answered");
}
else {
alert("Q2 Not Answered);
return false;
}
}
}
else {
alert("Q1 not answered");
return false;
}
}
I know this isn't the most elegant or efficient way to do this but that's another posting....
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
-- attempt to answer future question :)
What I always do is label the radio or checkboxes with the same name.
then in my javascript i can loop through them.
<script>
function chksurvey()
{
pass = false;
for(i=0;i<document.mySurve
{
if(document.mySurvey.quest
pass = true;
}
if(!pass)
{
alert("Please answer Question 1");
return false;
}
return true;
}
</script>
<form name='mySurvey' onsubmit='return chksurvey();'>
Question 1: ...
<input type='radio' name='question1' value='A'> A
<input type='radio' name='question1' value='B'> B
<input type='radio' name='question1' value='C'> C
</form>
Yup. I tried that. I'm developing in VS2003 and when I type "document.mySurvey." the drop-down doesn't list "question1" as an object I can select. It lists the values from the ID tags (R1, R2) in the radio buttons, but not the NAME tag(q1). Wierd. I even tried just ignoring Intellisense and typed "alert(document.mySurvey.q
<input type="radio" name="q1" value ="1" id="R1" onClick="showQs(1,1)"> 1-3 times / week</input>
<input type="radio" name="q1" value ="2" id="R2" onClick="showQs(1,2)"> 3 or more times / week</input>
<input type="radio" name="q1" value ="3" id="R3" onClick="showQs(1,3)"> Do not use cafeteria services</input>
So I should be able to iterate through for(i=0;i<document.mySurve
Any thoughts
I dont use VS2003... im a dreamweaver person.
I used VS a lil while ago and I know what you're talking about.
Some of the fields would show up in the auto popup thingie when your typing script, and some wont.
I basically ignored it and developed the page the way it should and it still seemed to work.
So I guess I don't know why VS2003 would be ignoring some of your fields.
But your alert of q1[0].value should still work.. heh wierd.
what if you alert(document.mySurvey.q1
I dont use VS2003... im a dreamweaver person.
I used VS a lil while ago and I know what you're talking about.
Some of the fields would show up in the auto popup thingie when your typing script, and some wont.
I basically ignored it and developed the page the way it should and it still seemed to work.
So I guess I don't know why VS2003 would be ignoring some of your fields.
But your alert of q1[0].value should still work.. heh wierd.
what if you alert(document.mySurvey.q1
HTML as posted above. Shouldn't this result in an array with the name "q1"?
<input type="radio" name="q1" value ="1" id="R1" onClick="showQs(1,1)"> 1-3 times / week</input>
<input type="radio" name="q1" value ="2" id="R2" onClick="showQs(1,2)"> 3 or more times / week</input>
<input type="radio" name="q1" value ="3" id="R3" onClick="showQs(1,3)"> Do not use cafeteria services</input>
the below code returns '3' for me.
-----------
<html>
<head>
<script>
function chk()
{
alert(document.myform.q1.l
}
</script>
</head>
<body>
<form name='myform'>
<input type="radio" name="q1" value ="1" id="R1" onClick="showQs(1,1)"> 1-3 times / week</input>
<input type="radio" name="q1" value ="2" id="R2" onClick="showQs(1,2)"> 3 or more times / week</input>
<input type="radio" name="q1" value ="3" id="R3" onClick="showQs(1,3)"> Do not use cafeteria services</input>
<input type='button' value='Check' onclick='chk();'>
</form>
</body>
</html>
Business Accounts
Answer for Membership
by: justinbilligPosted on 2005-07-20 at 07:02:08ID: 14484670
the Q2 not answered alert is missing a "
cked) || (document.mySurvey.R2.chec ked) || (document.mySurvey.R3.chec ked) )
cked) || (document.mySurvey.R2.chec ked) ) ecked) || (document.mySurvey.R22.che cked) || (document.mySurvey.R23.che cked) || (document.mySurvey.R24.che cked) )
and you should put parentheseiss around your if statemetns ( The whole if statement )
function valform()
{
if ((document.mySurvey.R1.che
{
alert("Q1 answered");
if ((document.mySurvey.R1.che
{
if ((document.mySurvey.R21.ch
{
alert("Q2 answered");
}
else
{
alert("Q2 Not Answered");
return false;
}
}
}
else
{
alert("Q1 not answered");
return false;
}
}