I am trying to have a div show if 2 options in a select2 box are chosen using jquery but am unsuccessful.
For example - my 2 choices are First and Second:
<select id="choose1" multiple="multiple">
<option value="first">First</option>
<option value="second">Second</option>
</select>
I have 2 divs that hidden:
<div id="first">
ABC
</div>
<div id="second">
XYZ
</div>
$('#first').hide();
$('#second').hide();
And now my jquery to show the divs:
$('#choose1').select2();
$('#choose1').change(function () {
var val = $(this).val();
var x = 'first';
var y = 'second'
var z = ['first','second'];
if (val == x) {
$('#first').show();
}
else if (val == y) {
$('#second').show();
}
else if (val == z) {
$('#first').show();
$('#second').show();
}
});
Any ideas on how I can get this to work?
Thanks.
Aucun commentaire:
Enregistrer un commentaire