Fairly new to jquery so I might be making a simple mistake but I just cant seem to find it. At the moment I have a select drop down that I want to send the user to the url that is built from the option they choose. At the moment I have this for my jquery:
$('#sizeSelect').change(function () {
var singleValue = $(this).find('option:selected').val();
var singleUrl = '/products/length' + '~' + escape(singleValue);
alert(escape(singleValue));
alert(singleUrl);
alert('/products/length' + '~' + escape(singleValue));
window.location = $(this).find('option:selected').attr('href', 'singleUrl');
});
I have my alerts in there for me to see how everything was being put together. When I get to my actual window.location the url that is built has [object%20Object] in it . So any help would much appreciated to a a somewhat new jquery user.
Why not send your users directly to the
singleUrlvariable?I’m not exactly sure what you’re trying to do on the last line:
$(this).find('option:selected')will return the selectedlielement, but it will be returned as an object. You will need to use.val()as you did earlier to return the value of theli.The second part,
.attr('href', 'singleUrl')will attempt to find thehrefattribute of thelielement (which doesn’t exist) and set its value tosingleUrl, which really won’t do anything for you.