Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML: Submit form on radio button check

Tags:

html

I have a form that displays two radio buttons (using PHP).

echo "<form action=\"next.php\" method=\"post\">";
   echo "<input type=\"radio\" name=\"paid\" value=\"0\" checked=\"checked\">No<br>";
   echo "<input type=\"radio\" name=\"paid\" value=\"1\">Yes<br>";
echo "</form>";

One of the radio buttons is always checked by default. If the user checks the other radio button, I would like the form to submit itself (without the user having to click a submit button).

like image 329
Juicy Avatar asked Sep 02 '13 00:09

Juicy


1 Answers

you can append this into your input:

onchange='this.form.submit();'

like:

echo "<form action=\"next.php\" method=\"post\">";
   echo "<input onchange='this.form.submit();' type=\"radio\" name=\"paid\" value=\"0\" checked=\"checked\">No<br>";
   echo "<input onchange='this.form.submit();' type=\"radio\" name=\"paid\" value=\"1\">Yes<br>";
echo "</form>";

DEMO

like image 90
Roko C. Buljan Avatar answered Oct 24 '22 14:10

Roko C. Buljan