1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help with a checkbox

Discussion in 'JavaScript' started by qwikad.com, Oct 25, 2016.

  1. #1
    This works fine, except the var total = 0; doesn't show unless you click the checkbox twice. How can I show that 0 right away when the checkbox is first loaded?

    https://jsfiddle.net/zf1psgw6/1/

    
    <input type="checkbox" value="1" id="add_one" >
    <div id="total"> </div>
    
    Code (markup):
    
    $("#add_one").click(function () {
    var chk = $("#add_one").val();
    var total = 0;
    if ($("#add_one").prop("checked") == true) {
    var gtotal = parseInt(total) + parseInt(chk);
    } else {
    var gtotal = parseInt(total);
    }
    $('#total').text(gtotal);
    });
    
    Code (markup):
     
    qwikad.com, Oct 25, 2016 IP
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #2
    qwikad.com, Oct 26, 2016 IP
    sarahk likes this.