Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to radio button change form action address
    text
    copied!<p><strong>How to make radio button change the form action address</strong></p> <p>I got a form which have the following</p> <p></p> <p>and a radio button</p> <pre><code>&lt;b&gt;Would you like to to make payment ? &lt;input type="radio" name="choice" value="yes"&gt;Yes &lt;input type="radio" name="choice" value="no" checked&gt;No&lt;/b&gt;' </code></pre> <p>If user selection is <code>no</code> (default checked) the form <code>action</code> will still be <strong>register_page4.php</strong></p> <p>but if user selected <code>yes</code> and press the submit button:</p> <pre><code>&lt;input id="btnSubmit" type="submit" value="Next" /&gt; </code></pre> <p>I would like the form action to be <strong>payment.php</strong> instead of <strong>register_page4.php</strong>, how do I achieve it.</p> <p>I make the changes and this is what I type</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="form1" method="post" action="register_page4.php"&gt; Would you like to make an appointment for collection ? &lt;input type="radio" name="collection" value="yes"&gt;Yes &lt;input type="radio" name="collection" value="no" checked&gt;No &lt;input id="btnSubmit" type="submit" value="Next" /&gt; &lt;/form&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/jquery-1.9.1.js"&gt;&lt;/script&gt; &lt;script&gt; jQuery(document).ready(function($) { var form = $('form[name="form1"]'), radio = $('input[name="choice"]'), choice = ''; radio.change(function(e) { choice = this.value; if (choice === 'yes') { form.attr('action', 'payment.php'); } else { form.attr('action', 'register_page4.php'); } }); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>But the result is still going to register_page4.php even I click on the radio button with yes, I try click on both and both still go to register_page4.php</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload