Reputation: 119
I am trying to pass a simple .js variable (prodID) into a jquery function that preselects a dropdown. I know the prodID variable has a value because document.write prints it out. I know that the jQuery works, because when I assign an arbitrary value (say....225) to the 'value =' variable, the dropdown selects as it should. I just can't get value='prod_id' to work. Is always null. What am I doing wrong?
var ProductID = "ProductID";
var prodID = getCookieValue(ProductID);
document.write(prodID);
changeDropDown(prodID);
function changeDropDown(prodID){
jQuery("#groupsel_0 option[value= 'prodID' ]").prop("selected", true);
jQuery('#groupsel_0').trigger('change');
};
I have tried not wrapping in a function too.
Upvotes: 0
Views: 110
Reputation: 2970
function changeDropDown(prodID){
jQuery("#groupsel_0 option[value= '" + prodID + "']").prop("selected", true);
jQuery('#groupsel_0').trigger('change');
};
you need to escape your string
Upvotes: 1