March 28, 200520 yr 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
March 28, 200520 yr 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
March 29, 200520 yr 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
Create an account or sign in to comment