[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Dynamic Redirect

Posted on 2009-07-11
5
Medium Priority
?
364 Views
Last Modified: 2013-12-13
I am trying to create a form that uses a dynamic type of redirect. I was hoping for a php or javascript solution (if it even exists)

For example:

I will have two radio buttons (one is YES and the second one is NO). I will also have a submit button labeled NEXT.

If YES is pressed and the Next Button is selected the user would go to Page 1.

If NO is pressed and the Next Button is selected the user would go to Page 2.

Thanks in advance experts
0
Comment
Question by:bmw040
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Assisted Solution

by:Xemorph
Xemorph earned 600 total points
ID: 24830873
Try this:
<html>
<head>
 <script type="text/javascript">
   function redirect(){
     var yes = document.getElementById('yes').checked;
  
     if(yes) window.location="page1.html";
     else window.location="page2.html";
 
   }
 </script>
</head>
<body>
   <input type="radio" id="yes" /> Yes <br />
   <input type="radio" id="no"  /> No <br />
   <input type="button" value="NEXT" onclick="redirect()" />
</body>
</html>

Open in new window

0
 
LVL 4

Expert Comment

by:Xemorph
ID: 24830878
Sorry, one error in my code.  add the name attribute to both radio buttons.  Make them the same.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 800 total points
ID: 24831045
You may want to process other information in the form, and to do that you may want to run a script on the server-side, instead of on the client-side in JavaScript.  If that is the case, this code will show you the way to do the dynamic redirect.

best regards, ~Ray
<?php // RAY_radio_redirect.php
error_reporting(E_ALL);
 
 
// GUIDANCE COPIED FROM THE OP
// If YES is pressed and the Next Button is selected the user would go to Page 1.
// If NO  is pressed and the Next Button is selected the user would go to Page 2.
 
 
// IF ANYTHING IS POSTED
if (!empty($_POST["my_radio"]))
{
 
 
//
// VALIDATE THE CONTENTS OF $_POST AND UPDATE A DATA BASE, ETC.
//
 
 
// SET THE DEFAULT (ERROR) PAGE
    $page = 'error.html';
 
// DETERMINE WHERE TO REDIRECT
    if ($_POST["my_radio"] == 'y') $page = 'page1.html';
    if ($_POST["my_radio"] == 'n') $page = 'page2.html';
 
// REDIRECT AND EXIT
    header("Location: $page");
    exit;
    
} // END OF PHP - PUT UP THE FORM WITH THE RADIO BUTTONS
?>
 
<form method="post">
<input type="radio" name="my_radio" value="y" />YES (PAGE 1)<br />
<input type="radio" name="my_radio" value="n" />NO (PAGE 2)<br />
<input type="submit" />
</form>

Open in new window

0
 
LVL 14

Assisted Solution

by:profya
profya earned 600 total points
ID: 24847666

<html>
<head>
 <script type="text/javascript">
   function GoToUrl(){
		var userOptions=document.forms[0].elements['userOption'];
		if (userOptions[0].checked)
			window.location=userOptions[0].value;
		else
			window.location=userOptions[1].value;
   }
 </script>
</head>
<body>
	<form>
   <input name="userOption" type="radio" value="www.domain1.com" checked/><label for="userOptions">www.domain1.com</label>
   <input name="userOption" type="radio" value="www.domain2.com"  /><label for="userOptions">www.domain2.com</label>
   <input type="button" value="Go" onclick="GoToUrl()" />
   </form>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:bmw040
ID: 31602435
Thanks for the solution!
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question