PHP2005 Posted March 28, 2005 Posted March 28, 2005 Hi, I am new in PHP. I am wonder if has anybody out there who can help me with some code? I have a form with 3 radio buttom and what I am trying to do is to have an if statement if in case the radio "Yes" is checked will take it to the page 1 If radio "No " is checked will take to page 2 If radio "other is checked will take to page 3 thank you, msei
Garry Claridge Posted March 28, 2005 Posted March 28, 2005 You can use the "onchange()" function. Maybe something like this: Yes <input type="radio" name="myradio" value="yes" onchange="document.location='page1.html';"> No <input type="radio" name="myradio" value="no" onchange="document.location='page2.html';"> Other <input type="radio" name="myradio" value="other" onchange="document.location='page3.html';"> Good Luck. Garry
Steve T. Posted March 29, 2005 Posted March 29, 2005 Hi, m! Garry's JavaScript onchange() is probably best, but if I were to do something like that in PHP, it would depend upon what was on the other pages. What you seem to be asking is how to change the form action page based on a user selection, but you usually cannot evaluate what a user does on a form until the form has been submitted (except w/JavaScript which is browser-side). So, you may want to consider taking the user to the same page first, no matter what, and then implementing your conditions. Then, based on the $_POST['myradio'] value, either show the appropriate information for each value OR use the form action page as a transition page only which will then use a meta-refresh to take the user to the appropriate page. TRANSITION... myformpage.php > transitionpage.php > page1.php, page2.php, or page3.php 3-PAGES-IN-1... I would also probably use a swtich( ) instead of if ( ) but that's up to you.... $myradio = $_POST['myradio']; swtich ($myradio) { case "yes": // all your yes code or include break; case "no": // all your no code or include break; case "other": // all your other code or include break; default: echo ("Only 'yes', 'no', or 'other' can be selected. <br> n"); } --ST
Recommended Posts
This topic is 7249 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now