javascript - How to stop Duplicate value in this code -


how stop duplicate value in code

html

   <ul class="care-ul">         <li><a><input type="checkbox" value="disease" /> disease</a></li>         <li><a><input type="checkbox" value="failure"/> failure</a></li>         <li><a><input type="checkbox" value="wounds"/>  wounds</a></li>         <li><a><input type="checkbox" value="afib"/> afib</a></li>     </ul> 

javascript

var carevalue = [];  function questioncount() {      $.each($('input[type="checkbox"]:checked'), function () {         var value = $(this).val();         carevalue.push(value);     });                 var json = json.stringify(carevalue);     var obj = json.parse(json);     $('.new-lists li').html(obj);         }  $(document).ready(function () {     $('#apply').click(function () {         questioncount();     }); }); 

you need intialize carevalue array in questioncount method everytime rather intializing outside.

function questioncount() {      carevalue = []; //now lose initial values new unique values coming     $.each($('input[type="checkbox"]:checked'), function () {         var value = $(this).val();         carevalue.push(value);     });                 var json = json.stringify(carevalue);     var obj = json.parse(json);     $('.new-lists li').html(obj); } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -