2

I have a select element that functions as a dropdown menu. Each option has a value that is a URL.

I want it so that every time any option is selected, the page will go to that option's value as a URL.

This is what I have so far, but I am not sure if I am on the right track:

$('userNav').change(function() {
        window.location.replace("http://" something with concatenation);
    });

Any help?

1
  • 2
    please use more self explanatory titles for your questions. Commented Mar 13, 2011 at 14:47

2 Answers 2

6
$('#userNav').change(function() {
     window.location = $(this).val();
});

Online demo: http://jsfiddle.net/amosrivera/Cg2yv/

Sign up to request clarification or add additional context in comments.

2 Comments

No need to wrap this in a jQuery object. this.value would work just as well.
Right thanks, i just like to have consistency, go with the jQuery syntax if i'm using jQuery as long as that doesn't hurt performance.
0

Try this code its working grt..

<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
$(function() {

    $("#submit").hide();

    $("#page-changer select").change(function() {
        window.location = $("#page-changer select option:selected").val();
    })

});
</script>
</head>
<body>
<?php
	if (isset($_POST['nav'])) {
		 header("Location: $_POST[nav]");
	}
?>
<form id="page-changer" action="" method="post">
    <select name="nav">
        <option value="">Go to page...</option>
        <option value="http://css-tricks.com/">CSS-Tricks</option>
        <option value="http://digwp.com/">Digging Into WordPress</option>
        <option value="http://quotesondesign.com/">Quotes on Design</option>
    </select>
    <input type="submit" value="Go" id="submit" />
</form>
</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.