javascript - Problems with Get / Set value to text -


i'm trying when press button (get value) set size of checkboxes text. make variable (numall) global, , convert tostring, still not working. idea solve solution?

demo

jquery:

$(function () {     // click function add card     var $div = $('<div />').addclass('sortable-div');     $('<label>title</label><br/>').appendto($div);     $('<input/>', {         "type": "text",             "class": "ctb"     }).appendto($div);     $('<input/>', {         "type": "text",             "class": "date"     }).appendto($div);     $('<input/>', {          "type": "text",              "class": "cbox"      }).appendto($div);     var cnt = 0,         $currenttarget;     $('#addcardbtn').click(function () {         var $newdiv = $div.clone(true);         cnt++;         $newdiv.prop("id", "div" + cnt);          $newdiv.data('checkboxes', []);          $('#useraddedcard').append($newdiv);         //      alert($('#useraddedcard').find("div.sortable-div").length);             });       $("#getbtn").on("click", function () {         var val = $("#customtextbox").val();         $currenttarget.find(".ctb").val(val);         $currenttarget.find(".date").val($("#datepicker").val());          var cboxval = numall;         var st = console.tostring(cboxval);         $currenttarget.find(".cbox").val(st);          $currenttarget.data('checkboxes', $('#modaldialog').data('checkboxes')); /* copy checkbox data card */          //$('#modaldialog').dialog("close");     });       var numall;  function updateprogress() {     var numall = $('input[type="checkbox"]').length;     var numchecked = $('input[type="checkbox"]:checked').length;      if (numall > 0) {         var perc = (numchecked / numall) * 100;         $("#progressbar").progressbar("value", perc)         .children('.ui-progressbar-value')         .html(perc.toprecision(3) + '%')         .css("display", "block");     } }   

you should use .tostring() method on number object:

    var st = cboxval.tostring(); 

otherwise can't find defining numall variable, had replace

var cboxval = numall; 

with:

var cboxval = numall === undefined ? 0 : numall; 

in order able perform mys tests.

here have updated version of js fiddle.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -