Submit HTML form with radio button

Posted by Shek on October 22, 2010 under HTML | Be the First to Comment | Total View: 53,889 views

Editor’s note: HTML form normally submitted with a button, however in some cases when the user wants to have an action (submit some data to another page) by clicking a radio button, a little javascript would do the job, and here is an example:

First we create a standard HTML form, however we do not put the action attribute:

<form name="aform" method="post" ></form>

Inside the form, we then include a radio button and javascript to submit the form to a PHP file ‘process.php’ when selected:

<form name="aform" method="post" >
<input type="radio" name="aradio" value="avalue" onClick="this.form.action= 'process.php'" >

Here we use onClick=”this.form.action= ‘process.php'” to submit the form.

Not what you want? Try a Search

Add A Comment