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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

radio buttons required field

Status
Not open for further replies.

Tee1212

Vendor
Mar 26, 2001
82
0
0
US
Hello--Can someone tell me how to make one of two radio buttons required when the form is validated? I seem to only be able to validate text fields.

Thanks in advance.
 
Thanks...I found that too, but couldn't get it to work. I guess his directions are over my head.
 
I believe there are extension for dreamweaver that are available for download or pusrchase that wold take care of it for you
Do a search for DW extension for validation
 
All you need to do is have a javascript function change the value of some variable when either of the radio buttons is selected. then on submission just check the value of that variable. Something along these lines
Code:
<script language="javascript">
var my_radio_val = ""
function validateRadio(theform){
if  (my_radio_val == "") {
	alert("You must select a fault category.");
	return false;
}
}
</script>
<form action="somepage.htm" onSubmit="return validateRadio(this);">
  <p>
    <input name="myRadio" type="radio" value="value1" onClick="my_radio_val='true'">
  </p>
  <p>
    <input name="myRadio" type="radio" value="value2" onClick="my_radio_val='true'">
</p>
  <p>
    <input type="submit" name="Submit" value="Submit">
  </p>
</form>

Cheech

[Peace][Pipe]
 
Thanks, Cheech. I found something I copy and pasted before I saw your response that worked... Now, I have problems with fields that are required based on the radio button selected. See my next thread.... Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top