Skip to content Skip to sidebar Skip to footer

How To Change Selected Attribute Via Javascript

I have an issue that I'm trying to solve. Need some advice to the right direction: With Prestashop when creating combinations, you have a dropdwon-list on product page where custom

Solution 1:

Your quotes are wrong, looking at the console you would get the error Uncaught SyntaxError: Unexpected number

$('#group_4 option[value='58']').attr('selected', 'selected').change();
                         ^  ^

should be

$('#group_4 option[value="58"]').attr('selected', 'selected').change();

Solution 2:

To change the selected option, you can simply change the value of the select element using plain JS:

document.getElementById('group_4').value = 58;

You'd still need to trigger the change event after that, though.

See a simple example here: http://jsfiddle.net/BgBGL/1/ (uses alert as onchange callback)

Post a Comment for "How To Change Selected Attribute Via Javascript"