Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my current code:

HTML
<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
<body>
    <div>
        <h1>Here are some additional Icing Recipes</h1>

        <select name='courses' multiple="multiple" size='2' onchange="location = this.value;">
            <option value="">Select an option</option>
            <option value="" disabled selected></option>
            <option value="" disabled selected></option>
            <font color='#ffffff'>
            <option value="https://www.twosisterscrafting.com/baileys-irish-cream-buttercream-frosting/" target="_blank">The Best Baileys Irish Cream Buttercream Frosting</option>
        </select>
    </div>
</body>
</html>


The above code is part of a dropdown so Tags don't work.

The above code does run but does not open a new page. Since I am a self-taught beginner, I am not certain what is wrong.

What I have tried:

I have 2x checked my code & since I am a beginner I am not certain what is wrong.
Posted
Updated 22-Mar-23 7:35am
v3

Use an a tag instead;

HTML
<a href="https://www.twosisterscrafting.com/baileys-irish-cream-buttercream-frosting/" target="_blank">The Best Baileys Irish Cream Buttercream Frosting</a>
 
Share this answer
 
A <select> element cannot just natively open a window upon an option selection, you have to use a <a> element to do that. Otherwise, you need to resort to using Javascript to manage this for you. You can combine Javascript with special attributes called data attributes[^] which allow us to store additional data against any element.

Here's an example JSFiddle with what you might need[^]

In the Javascript we get the select element, we register a change listener, and then when the event triggers we get the URL from the selected option (from the data-url attribute) and open the new window/tab.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900