I have a shoppingcart that displays product options in a dropdown menu, and I want to make some other fields on the page only visible if they select "Yes" in the previous option. The problem is that the shopping cart also includes the price modifier in the text, and that can be different for each product. So if I do this it works:
$(document).ready(function() {
$('select[id="Engraving"]').change(function() {
var str = $('select[id="Engraving"] option:selected').text();
if (str == "Yes (+ $6.95)") {
$('.engraving').show();
} else {
$('.engraving').hide();
}
});
});
However I would rather use something like this:
$(document).ready(function() {
$('select[id="Engraving"]').change(function() {
var str = $('select[id="Engraving"] option:selected').text();
if (str *= "Yes") {
$('.engraving').show();
} else {
$('.engraving').hide();
}
});
});
Which doesn't work.
I only want to perform the action if the selected option contains the word "Yes", and would ignore the price modifier.
I appreciate any help.