Karthik
Karthik

Reputation: 3281

How do a select option selection pick from some other page using HTML and JavaScript only?

I have two pages, one where the user chooses an option (A) the other where that option is used (B). When the users have made their choice, they should be redirected to page B. I have an idea on how to pass the choice value in URL, but how can I retrive the correct option in page B. I am using only HTML and JavaScript. (client side code only please)

Upvotes: 1

Views: 525

Answers (1)

Tim Down
Tim Down

Reputation: 324587

Do you mean something like this?

<script type="text/javascript">
    function redirect(sel) {
        var url = sel.options[sel.selectedIndex].value;
        if (url) {
            window.location.href = url;
        }
    }
</script>

<select onchange="redirect(this);">
    <option value="">Please select</option>
    <option value="http://www.google.com/">First (Google)</option>
    <option value="http://www.yahoo.com/">Second (Yahoo)</option>
</select>

Upvotes: 1

Related Questions