adding to a javascript function using a html checkbox -


i have seen questions answer adding object believe different involves html checkbox.

so need put in place html checkbox add or subtract (depending on checked) selection au01,2,3,4 etc , apend function have. function have made.

$(document).ready(function() {       var data = {};       var featuresdata = [];       var emotionsdata = {};       var emotions = [{         title: "happiness",         aus: ["au04", "au12"]   //this bit want add       }]; 

so says aus: ["au04", "au12"] have set @ au4 , 12 wanting put text "au**" part of function. want able add in additionals (or subtract them) depending on checkbox clicked. each checkbox represent au. hope makes sense.

in following code, when submit button clicked, empty array created. iterate on checked checkboxes in specific div , push in array attribute values. finally, solution printed out.

$('#check').click(function(){    var checked = [];    $('#checkboxes input:checked').each(function(){      checked.push($(this).attr('data-au'));    });    $('#out').text(json.stringify({aus: checked}));  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>    <div id="checkboxes">    <input type="checkbox" data-au="au1" />au1<br />    <input type="checkbox" data-au="au2" />au2<br />    <input type="checkbox" data-au="au3" />au3<br />    <input type="checkbox" data-au="au4" />au4<br />  </div>    <button id="check">check checkboxes</button>    <div id="out"></div>


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -