I have a visible and a hidden select option. When user selects something, I want to get the selected option and search text in hidden select option. Because I need the val of hidden select option that matches with the selected text. First I tried;
var testx=document.getElementById("priceMatrix");
testx.options[testx.selectedIndex].text=toAdd+"|"+cupSize;
it works, I can set text but still can not set the value. and I tried secondly;
var myText = toAdd+"|"+cupSize;
$('#priceMatrix').filter(function () { return $(this).html() == myText; }).prop('selected', true)
var alertText = $("#priceMatrix option:selected").val();
alert(alertText);
but still it does not work, $("#priceMatrix option:selected").val(); gives the first row's value, not the selected one.
So, what is the problem? is it about button click?
Aucun commentaire:
Enregistrer un commentaire