Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    23
    Member #
    25361
    Hi,

    I am trying to use switch statement to redirect user to another website when they select it from a drop down box.

    please i need help on this to work .i have code here which i want you to help me out to work if possible.
    Code:
    <html>
    <?php
    $my_links=" ";
    switch($my_links){
    case"yahoo":
    echo "<a href='http://www.yahoo.com'></a>";
    break;
    case"google":
    echo "< a href='http://www.google.com'></a>";
    break;
    case"facebook":
    echo "<a href='http://www.facebook.com'></a>";
    break;
    default:
    echo"you do not have the permission to thses links";
    break;
    }
    ?>
    <form>;
    <select name="$my_links">
    <option value="yahoo">Yahoo</option>
    <option value="googl">Google</option>
    <option value="facebook">Facebook</option>
    </select>
    </form>
    <html>
    Thanks.Clement Osei.

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,824
    Member #
    5580
    Liked
    726 times
    Do you want them to swich as soon as they click on the option,
    or are you going to have a submit button? There are several ways
    of doing this, including Javascripting.

    I found this Javascript example via Google:
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
    <
    HTML
     <
    HEAD
      <
    TITLEExample onchange and submit </TITLE
     
      <
    script language="javascript">     
       function 
    myChangeHandler()  
       { 
        
    window.open(this.options[this.selectedIndex].value'_blank'); 
        
    this.form.submit(); 
       } 
      
    </script> 
     </HEAD> 
     
     <BODY> 
     <form id="myform1" action="test.html"> 
      <select onchange="myChangeHandler.apply(this)"> 
        <option>Please select....</option> 
        <option value="http://stackoverflow.com">Stackoverflow</option> 
        <option value="http://twitter.com">Twitter</option> 
        </select> 
      </form> 
     </BODY> 
    </HTML> 

    .


  4. #3
    Member LavaEagle's Avatar
    Join Date
    Dec 2010
    Location
    Seattle, WA
    Posts
    46
    Member #
    25843
    Liked
    1 times
    PHP Code:
    case "yahoo":
        
    header('location: http://www.yahoo.com');
    break; 
    That will redirect the user in the same window to a new site.

  5. #4
    Junior Member
    Join Date
    Dec 2010
    Posts
    23
    Member #
    25361
    Hi LavaEagle,

    Thank you for your helpful post and to every one that helped me solve this.

    May God bless you all.

    Clement Osei.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 01:47 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com