Reputation: 1
I am using the following code to display div's according to the select option in the HTML using jquery. this works fine.
however, I need to know how I can display both of them if the option front an back
is selected?
here is my current code:
JS:
<script language="javascript">
$(function() {
$('#Field169').change(function(){
$('.myDivs').hide();
$('#' + $(this).val()).show();
});
});
</script>
html:
<div class="myDivs" id="Front" align="center>Front</div>
<div class="myDivs" id="Back" align="center>Back</div>
<select id="Field169">
<option value="WHAT DO I NEED HERE??">Front and Back</option>
<option value="Front">Front Only</option>
<option value="Back">Back Only</option>
</select>
Upvotes: 0
Views: 124
Reputation: 2648
$('#Field169').change(function(){
var getvalue=$(this option: selected).text();
if(getvalue=='Front and Back')
{
$('#front').show();
$('#back').show();
}
});
Upvotes: 0
Reputation: 58462
You could leave the value blank and then change your jquery:
$('#Field169').change(function(){
var selectedValue = $(this).val();
if (selectedValue === '') {
$('.myDivs').show();
} else {
$('.myDivs').hide();
$('#' + selectedValue).show();
}
});
Upvotes: 0
Reputation: 1758
You can't do it if you're referencing by IDs, but if you gave them classes with those same names instead, and your option values looked like .front
and .back
then your combined option could have the value value=".front, .back"
and the selector would get both of them. You would want to change the function to look like:
$($(this).val()).show();
rather than selecting by ID
Upvotes: 1