Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

If/Else with radio button

Featured Replies

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

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

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

  • Author

Thanks Steve and Gary.

I will give a try.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.