|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to validate radio buttons in an asp script, asap
<i><b>Originally posted by : Jason (jroscoe@riteaid.com)</b></i><br />I have an asp script that uses radio buttons to select certain options, but I get an error if none of them are selected. How can I validate that these options are selected, and if they are not selected, have an alert message telling the user they must select one button? Thanks
|
|
#2
|
|||
|
|||
|
<i><b>Originally posted by : antony (antovelan@usa.net)</b></i><br />for validating the selection of radio button before submitting into asp page u have to use client side validation using javascript.so write one function in javascript like checkradio then call the function in onClick event of submit button,the sample code given below.<br /><br />sample<br />------<br /><br /><form name=f1 ><br /><br /><script language=javascript><br />function checkradio()<br />{<br />for (i=0;i<document.f1.elements.length;i++)<br />{<br /> if (document.f1.elements[i].type=="radio")<br /> {<br /> if (document.f1.elements[i].checked==true && document.f1.elements[i].name=="sex")<br /> return true;<br /> }<br />}<br />alert("Select At least one value from sex")<br />return false;<br />}<br /></script><br /><input type=radio name=sex value="M">Male<br /><input type=radio name=sex value="F">FeMale<br /><input type=submit value=ok onClick="return checkradio()"><br /></form><br /><br /><br />thankx<br />antony<br /><br /><br />
|
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > How to validate radio buttons in an asp script, asap |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|