Click to See Complete Forum and Search --> : onclick="this.form.submit" not submitting


bunner bob
01-06-2003, 08:26 PM
I'm trying to get a form to submit when a radio button is selected (without having to click a submit button). It doesn't seem to work - in fact nothing at all happens when I click one of the radio buttons.

I tried removing the <input type="submit"> tag and then it appears that the form submits (it reloads) but no data shows up at the database.

When I click the <input type="submit"> button it submits correctly.

Here's the code:

<form method="post" action="/choushow/edithome.php">

<input type="hidden" name="choosescheme" value="yes">

<table border="1" cellspacing="0" cellpadding="5">

<tr><td><a href="/choushow/edithome.php?homeschemeid=3&editentry=yes">The booger look</a></td>
<td><input type="radio" name="homeid" value="3" onclick="this.form.submit()" checked></td>
</tr>
<tr><td><a href="/choushow/edithome.php?homeschemeid=4&editentry=yes">The monkey look</a></td>
<td><input type="radio" name="homeid" value="4" onclick="this.form.submit()" ></td>
</tr>
</table>
<p><input type="Submit" name="submit" value="Select scheme to use"></p>

</form>

Any suggestions?

swon
01-06-2003, 08:38 PM
Just a little mistake, man:

<input type=submit name=submit

the name attribute is bad. Rename it to anything else and it will works!

bunner bob
01-09-2003, 11:57 AM
Actually there was one more factor - I of course didn't mention that I was submitting this to a PHP script, which processes the form if ($submit). When I renamed my submit button (or removed it actually) there was nothing in the form sending the variable $submit, so it didn't get processed. I ended up adding a new condition to if($submit): if ($submit || $choosescheme) and now it works nicely.

I thought that if you submitted a form, period, a variable called "$submit" was sent, but turns out you have to NAME your submit button "submit" (which makes sense when I think about it).

Anyway, thanks for steering me in the right direction!

swon
01-09-2003, 01:08 PM
You can also use the $HTTP_POST_VARS for checking of a form has been submitted.