-1

I require guidance on how to code dropdown list that can navigate to another page. For example, dropdown list have Youtube, Google, Facebook. If user choose YouTube in dropdownlist, upon click "submit" button. The page will go to YouTube.

I use switch case php with echo " location.href='https://www.google.com'" but the upon click submit. It didn't respond.

<select id="dropwdown1" name="dropdown" disabled="true">
    form method="post" action="?">  
        <option disabled selected="select">---Select Web---</option>
        <option value="1">YouTube</option>
        <option value="2">Google</option>
        <option value="3">Facebook</option>
</select>
            
<input type="submit" value="SELECT">
</form>
<?php
switch ($_POST['dropdown'])  { 
    case "1": 
        echo "<script> location.href='https://www.youtube.com'</script>";
        exit;
}
case "2": 
    echo "<script> location.href='https://www.google.com'</script>";
    exit;
}
case "3": 
    echo "<script> location.href='https://www.facebook.com'</script>";
    exit;
} ?>
mickmackusa
  • 43,625
  • 12
  • 83
  • 136
DTech
  • 11
  • 2
  • This is not Java – JayC667 Jul 21 '22 at 03:38
  • @JayC667 sorry, i thought – DTech Jul 21 '22 at 03:42
  • 1
    After I've removed the excess spacing from your snippet, do you see how horribly broken it is? Tabbing your code properly is an important part of being a good programmer and eliminating silly mistakes -- like writing a broken form tag inside of a select tag. – mickmackusa Jul 21 '22 at 03:53
  • [Potentially relevant](https://stackoverflow.com/q/5150363/2943403) and [this](https://stackoverflow.com/q/36528708/2943403) and [this](https://stackoverflow.com/q/12388954/2943403) and [this](https://stackoverflow.com/q/33419682/2943403) – mickmackusa Jul 21 '22 at 03:57

1 Answers1

0

First Time writing an answer in stackoverflow but I think instead of writing Youtube Directly you add like a link inside the Option so something like this <option value="1"><a href="https://www.youtube.com/" target="__blank">Youtube</a> </option> I am not sure if this is what you were trying to say but yea