Error calling jQuery html method

I make my first raid on javascript + jQuery, creating a simple page, but encountering errors, I'm sure this is something stupid, but I looked through the code several times and can not detect it.

The error I am getting is below:

Error image

All the code below (I changed the dynamic '#' + elementname + 'perc'to a string and I get the same error), can anyone suggest any information?

<DOCTYPE html>
<html>
    <head>
        <script src="js/jquery.js"></script>
        <!--<script src="js/dealercalc.js"></script>-->
        <script type="text/javascript">

$(document).ready(function(){
  $(".val-adjust").click(function(){
    var name = $(this).attr('name');
    var bit = $(this).attr('value');

    setvalue(name,bit);

    //discountbits['basic'] = false;
    //$("#basedisper").text(discountlist['basic']);
  });
  $("#basdisyes").click(function(){
    discountbits['basic'] = true;
    //$("#test1").html("<b>Hello world!</b>");
  });
  $("#btn3").click(function(){
    $("#test3").val(gettotal());
  });
}
);

function getpercbypurc(value){
    return 0;
};

function setvalue(elementname,yesno){
    discountbits[elementname] = yesno;
    if (yesno) {
        $("#basicperc").hmtl(discountlist[elementname] + "%");
    } else {
        $('#' + elementname + 'perc').hmtl("0%");
    }
};

function gettotal() {
    var total = 0;

    for (var i=0; i<keys.length; i++){
        if (discountbits[keys[i]] = true) {
            total += discountlist[keys[i]];
        }
    }

    return total;
};

function displaytotal(){
    $('#totalper').html(gettotal());
};

var keys = ['basic', 'marketing'];

var discountlist = {
    basic:20,
    marketing:2
};

var discountbits = {
    basic:true,
    marketing:false
};





        </script>
    </head>

    <body>

        Base Discount<br>
        <button class="val-adjust" name="basic" value="false">No</button>
        <button class="val-adjust" name="basic" value="true">Yes</button>
        <span id="basicperc">0</span>
        <br>
        <br>

        Marketing Plan<br>
        <button class="val-adjust" name="marketing" value="false">No</button>
        <button class="val-adjust" name="marketing" value="true">Yes</button>
        <span id="marketingperc">0</span>
        <br>
        <br>

        Total<br>
        <span id="totalper">0</span>
    </body>
</html>
+5
source share
4 answers

You have the wrong spelling for html, there hmltmust behtml

Edit

$("#basicperc").hmtl(discountlist[elementname] + "%");

For

$("#basicperc").html(discountlist[elementname] + "%");
+4
source

you have a typo

$("#basicperc").hmtl(discountlist[elementname] + "%");
         //-----^^^^---here

it should be

$("#basicperc").html(discountlist[elementname] + "%");
+4
source

, html hmtl:)

+4

. html, hmtl!

+3

All Articles