Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  8] [ 3]  / answers: 1 / hits: 24517  / 9 Years ago, thu, october 22, 2015, 12:00:00

I'm trying to use bootstrap multiselect to set the visibility of some columns in a table via the jQuery toggle() function. For each column chosen in the dropdown I want to either show or hide it depending on it being selected or not.
But I clearly do not understand how to use the onChange event to make this work.
Would someone please show me the correct syntax.



My javascript and HTML is as follows:



  <script type=text/javascript>
$(document).ready(function() {
$('#showops').multiselect({
maxHeight: 300,
buttonWidth: '150px',
includeSelectAllOption: true,
allSelectedText: 'Showing All',
onChange: function(element, checked) {
if(checked == true){
if (element == '1') { $(.toggleG).toggle(); }
else if (element == '2') { $(.toggleE).toggle(); }
}
}
});
});
</script>

<select id=showops multiple=multiple>
<option value=1> Show Grid </option>
<option value=2> Show eMail </option>
<option value=3> Show Lat/Lon </option>
<option value=4> Show Last Name </option>
<option value=5> Show TOD </option>
</select>

More From » jquery

 Answers
15

This fixed it.



onChange: function(option, checked, select) {
var opselected = $(option).val();
if(checked == true) {

if (opselected == '1') { $(.toggleG).toggle(); }
if (opselected == '2') { $(.toggleE).toggle(); }
if (opselected == '3') { $(.toggleLAT).toggle(); $(.toggleLON).toggle();}
if (opselected == '4') { $(.toggleLN).toggle(); }
if (opselected == '5') { $(.toggleTOD).toggle(); }
} else if(checked == false)
if (opselected == '1') { $(.toggleG).toggle(); }
if (opselected == '2') { $(.toggleE).toggle(); }
if (opselected == '3') { $(.toggleLAT).toggle(); $(.toggleLON).toggle();}
if (opselected == '4') { $(.toggleLN).toggle(); }
if (opselected == '5') { $(.toggleTOD).toggle(); }
}
}

[#64633] Wednesday, October 21, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jacie

Total Points: 490
Total Questions: 111
Total Answers: 105

Location: Mali
Member since Sat, Feb 12, 2022
2 Years ago
;