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

Submit a form when clicking a radiobutton

Status
Not open for further replies.

blekfis

Programmer
Oct 19, 2001
38
SE
I've got a simple voting with 5 radiobuttons. I want it to be submitted when one is clicked, without having to click on a submitbutton. How do I do this?
 
Code:
<input type="radio" blah blah blah [b]onclick="this.form.submit();"[/b]>
 
Use the onclick handler on each radio button and submit the form using the submit() function.
here's a working example to get you started:
Code:
<html>
<head>
<title>Blah</title>
<script language=JavaScript>
function radioSubmit(candidate) {
   if (confirm("Are you sure you want to vote for " + candidate + "?")) {
      submit();
   }
}
</script>
</head>
<body>
<form name=blahForm>
<input type=radio name=vote value='Bob' onclick='radioSubmit(this.value)'>Bob<br>
<input type=radio name=vote value='Sue' onclick='radioSubmit(this.value)'>Sue<br>
<input type=radio name=vote value='Harry' onclick='radioSubmit(this.value)'>Harry<br>
<input type=radio name=vote value='Fred' onclick='radioSubmit(this.value)'>Fred<br>
<input type=radio name=vote value='Bill Clinton' onclick='radioSubmit(this.value)'>Bill Clinton<br>
</form>
</body>
</html>

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top