Reputation: 1
I want to use a <select>
drop-down to set the href
of a link to different anchor values.
Thanks in advance
I currently have this JS:
var destinationchange = $("#destination").val();
$(document).ready(function() {
$("#destination").change () {
$("#engage").attr("href" , destinationchange);
});
});
And this HTML:
<select id="destination">
<option value="#1">1</option>
<option value="#2">2</option>
</select>
<a title="engage" id="engage">Engage</a>
Upvotes: 0
Views: 1038
Reputation: 22711
Try this,
$("#destination").change (function() {
$("#engage").attr("href", $(this).val());
});
DEMO: http://jsfiddle.net/aVqh9/
Upvotes: 1
Reputation: 318212
You get the value on pageload, and never change it. You need to get the value in the event handler
$(document).ready(function() {
$("#destination").on('change', function() {
$("#engage").prop("href" , this.value);
});
});
Upvotes: 0