Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript form validation query

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
how can i validate the following radio buttons so that an alert is produced if the values of each button are the same ??

Do you like cricket ?
Yes<input type=&quot;radio&quot; name=&quot;cricket&quot; value=&quot;yes&quot;>
No<input type=&quot;radio&quot; name=&quot;cricket&quot; value=&quot;no&quot;>
Or softball ?
Yes<input type=&quot;radio&quot; name=&quot;softball&quot; value=&quot;yes&quot;>
No<input type=&quot;radio&quot; name=&quot;softball&quot; value=&quot;no&quot;>

I want it so that they can only choose yes for question but must answer for both.

Currently script looking like this, makes sure they answer ok, but unable to validate it so that the two fields are different-

if (!(form.cricket[0].checked || form.cricket[1].checked))
{ some function about missing info }
if (!(form.softball[0].checked || form.softball[1].checked)) { some function about missing info}

above works fine

if((form.cricket.value) == (form.softball.value))

above doesn't, any ideas ?????


thanks
 
why can't you use the .checked ?? !!! you're using it right above !!!
if ((form.cricket[0].checked && form.softball[0].checked)||(form.cricket[1].checked && form.softball[1].checked))
alert(&quot;they can't be both true or both untrue !!&quot;)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top