
How to validate radio button , dropdown list and list box using onsubmit event..please give me a sample example..If we do not select any option,it shows an error..

Hello Friend,
Try this:
<Script language = JavaScript>
function validate() {
if(document.f1.choose.selectedIndex==""){
alert ( "Please select Dropdown value!" );
return false;
}
if ( ( document.f1.radios[0].checked == false ) && ( document.f1.radios[1].checked == false ) ){
alert ( "Please choose Radio Button!" );
document.f1.radios[0].focus();
return false;
}
return true;
}
</SCRIPT>
</HEAD>
<form name="f1" onsubmit ="return validate();">
<SELECT name = choose>
<OPTION VALUE = "select">select</OPTION>
<OPTION VALUE = "NE" >North East</OPTION>
<OPTION VALUE = "NW">North West</OPTION>
<OPTION VALUE = "SE">South East</OPTION>
<OPTION VALUE = "SW">South West</OPTION>
<OPTION VALUE = "Midlands">Midlands</OPTION>
</SELECT>
<input type="radio" name="radios" value="male">Male <input type="radio" name="radios" value="Female">Female<br /><br />
<input name="Submit" value="Send" type="submit" >
</form>
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.