Forum Moderators: coopster

Message Too Old, No Replies

Simplifying a form in PHP

Moving from a dual click to single click form

         

technossomy

12:36 pm on Aug 24, 2005 (gmt 0)

10+ Year Member



Dear all

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

StupidScript

4:47 pm on Aug 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Moving to one-click means client-side.

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]

mcibor

5:09 pm on Aug 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's more a javascript problem, but here goes one of the many answers:

<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">

technossomy

9:24 pm on Aug 24, 2005 (gmt 0)

10+ Year Member



Thanks both, I have tried it and it works (after some minor mods made of course).

Tech