Radio button on a form on Submit
Moderator: General Moderators
Radio button on a form on Submit
I have a form with 2 radio buttons at the bottom...1 is "Agree" and the second is "Don't Agree" ... On Submit I would like the form to go to POST only if the "Agree" button was pressed and go to another page (link) if the "Don;t Agree" button was selected... On Submit for both... Thanks ...
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Radio button on a form on Submit
Not about theory or design, it's a PHP/HTML question, so moved to PHP Code.
(#10850)
Re: Radio button on a form on Submit
There are a couple of ways to do that. One is to make the "Agree" button the type='submit' button and the other one a type='button' with an onClick='document.location("xxxxx.php");' or just make the "Don't Agree" an anchor <a> element. You can do fancier things with Javascript, but then occasionally you might have a visitor who has JS disabled in their browser.podarum wrote:I have a form with 2 radio buttons at the bottom...1 is "Agree" and the second is "Don't Agree" ... On Submit I would like the form to go to POST only if the "Agree" button was pressed and go to another page (link) if the "Don;t Agree" button was selected... On Submit for both... Thanks ...
Re: Radio button on a form on Submit
Thank you so much Jack of Zircons, and I don't mean to sound 'goofballish", but I'm extremely new to php and web design, so I don't quite understand how that could be implemented in my code; Thank you again..
<div id="spryradio1">
<table width="673">
<tr>
<td width="334"><label>
<input type="radio" name="Disclaimer" value="I Agree" id="Disclaimer_0" />
I Agree</label></td>
<td width="327"><input name="Disclaimer" type="radio" value ="Disagree" id="Disclaimer_2"/>
Disagree</td>
</tr>
</table>
<span class="radioRequiredMsg">Please make a selection</span></div></td>
</tr>
<tr>
<td colspan="2"><p> </p></td>
</tr>
<tr>
<td height="34" colspan="2"><div align="center">
<input type="submit" name="Submit" id="Submit" value="Submit" />
<input type="reset" name="Reset" id="Reset" value="Reset" />
</div></td>
</tr>
<div id="spryradio1">
<table width="673">
<tr>
<td width="334"><label>
<input type="radio" name="Disclaimer" value="I Agree" id="Disclaimer_0" />
I Agree</label></td>
<td width="327"><input name="Disclaimer" type="radio" value ="Disagree" id="Disclaimer_2"/>
Disagree</td>
</tr>
</table>
<span class="radioRequiredMsg">Please make a selection</span></div></td>
</tr>
<tr>
<td colspan="2"><p> </p></td>
</tr>
<tr>
<td height="34" colspan="2"><div align="center">
<input type="submit" name="Submit" id="Submit" value="Submit" />
<input type="reset" name="Reset" id="Reset" value="Reset" />
</div></td>
</tr>
Re: Radio button on a form on Submit
my suggestion :
Use javascript to validate on the client side if the selected radio button is Agree or not.
Then display an alert message if the user didnt agree.
You didnt want the form to be posted to the other page. So its better to use a client side validating javascript.
Other way:
In the posted file (action file), put an if else statement for the posted value of radio button and redirect back if the user hasnt checked on what you wanted him/her to check.
Use javascript to validate on the client side if the selected radio button is Agree or not.
Then display an alert message if the user didnt agree.
You didnt want the form to be posted to the other page. So its better to use a client side validating javascript.
Other way:
In the posted file (action file), put an if else statement for the posted value of radio button and redirect back if the user hasnt checked on what you wanted him/her to check.
Re: Radio button on a form on Submit
I'm afraid I can't make much sense out of that little scrap of code, because it is obviously out of context with all the references it contains. If you are not an HTML coder, though, you will have a hard time doing HTML coding, and you're probably not going to be able to pick it up in a forum like this.
Here's basically what I was saying:
Here's basically what I was saying:
Code: Select all
<form method='post' action='somescript.php'>
// ... all the contents of your form
<input type='submit' value='I Agree'>
<input type='button' value='I Disagree' onClick='document.location("otherpage.html");'>
</form>