javascript - Issue removing duplicate val() in :checked .map function -


i use insight or helpful reference on checking values on selected checkboxes , if there duplicates, return one.

i'm working on software trial wizard using bootstrap wizard. first tab "solutions catalog" user can filter through hundreds of solutions. many solution types duplicate apply multiple industry types.

once user makes selections go tab 2 , review selections. i'm able map :checked , join values in custom separator in next step can't figure out how show 1 instance of duplicate value.

for example, user might select 2 types of "audits" customized solution. however, provisioning team wants know want "audit" module.

<input type="checkbox" class='selection' value="audits" name="audits - manufacturing"> <input type="checkbox" class='selection' value="audits" name="audits - electrical"> <input type="checkbox" class='selection' value="audits" name="audits - retail"> <input type="checkbox" class='selection' value="trading" name="trading - manufacturing"> <input type="checkbox" class='selection' value="trading" name="trading - retail"> 

my current code outputting multiple selections of same value , kinda stuck on how handle this.

$(document).ready(function() { $('#rootwizard').bootstrapwizard({     onnext: function(tab, navigation, index) {         if (index == 1) {             // make sure entered solutions             if (!$('.selection:checked').val()) {                 alert('please select solution try');                 $('.selection').focus();                 return false;             }         }         // show selections in next tab         $('#showselection').html('<li>' + $('.selection:checked').map(function() {             return $(this).val();         }).get().join('</li><li>') + '</li>');       }     }); }); 

you use array store values have seen. like:

$(document).ready(function() { $('#rootwizard').bootstrapwizard({     onnext: function(tab, navigation, index) {         if (index == 1) {             // make sure entered solutions             if (!$('.selection:checked').val()) {                 alert('please select solution try');                 $('.selection').focus();                 return false;             }         }         var selections = [];         // show selections in next tab         $('.selection:checked').each(function() {              var value = $(this).val()             if ($.inarray(value, selections) < 0){                selections.push(value);             }         })         $('#showselection').html('<li>' + selections.join('</li><li>') + '</li>');       }     }); }); 

fiddle: http://jsfiddle.net/2a460tfc/10/


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -