mercredi 27 septembre 2017

Jquery display checkbox`s value in div

I have this script which lets me to display value (text) which is next to the checkbox (aspx). On checkbox change text is shown in the div separated by commas. Somehow if any of the checkbox is checked and then di-checked, the value does not disappear from JobIDs var. What im missing here?

 $(document).data('JobNumbers', "");
 $('[id*=projectchk] input').change(function() {
    var JobIDs = "";
    var JobIDs = $(':checked').map(function() {
        return $(this).closest("span").find("label").html();
    }).get().join(', ');
    var JobNumbers = "<label> Reference Job #:</label> " + JobIDs;
    $('#job_numbers').html(JobNumbers);
    if (JobIDs != "") {
        $(document).data('JobNumbers', JobNumbers);
    }
    return false;
 });

So if 3 checkboxes are selected it shows: enter image description here

But even if I di-select all of them it still shows the last one: enter image description here

Thanks.




Aucun commentaire:

Enregistrer un commentaire