Forum Moderators: coopster
I have a radio button form as below:
<html>
<body>
<form name="myForm" action="foo.php" method="POST">
<input type="radio" name="gender" value="M">Male</input>
<input type="radio" name="gender" value="F">Female</input>
<input type="submit" value="Go">
</form>
</body>
</html>
What I prefer however is a form with identical functionality, but requires only a single click, something as such:
<html>
<body>
<form name="myForm" action="foo.php" method="POST">
<a href="?">Male</a> ¦ <a href="?">Female</a>
</form>
</body>
</html>
Does anyone know the correct syntax for this, provided I am programming server-side?
For instance, could I use the onclick event here and if so, what is its syntax in this case?
Even a pointer to a tutorial would be helpful.
Thanks in advance
Tech
You're correct in that the client-side Javascript onclick event is what you're looking for.
<input type="radio" name="gender" value="M" onclick="this.form.submit()" /> Male would do it.
W3Schools Javascript Tutorial [w3schools.com]
The ever-great-to-have-around Javascript QuickReference from Guru Danny Goodman [dannyg.com]
<html>
<body>
<form name="myForm" action="foo.php" method="POST">
<input type="radio" name="gender" value="M" onClick="document.myForm.submit();">Male</input>
<input type="radio" name="gender" value="F" onClick="document.myForm.submit();">Female</input>
<input type="submit" value="Go">
</form>
</body>
</html>
Best regards
Michal Cibor
PS This uses dom model. If you wish you can change it to: onClick="getElementById("FormId").submit();" and <form name="myForm" id="FormId" action="foo.php" method="POST">