Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when calling jQuery html method

I am making my first foray into javascript + jQuery, designing a simple page but encountering errors, I'm sure it's something silly but I've been over the code several times and can't spot it.

The error I receive is below:

Error image

The entire code is below (I've changed the dynamic '#' + elementname + 'perc' to a string and I get the same error), can anyone offer any insight?

<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>
like image 485
bendataclear Avatar asked Mar 27 '13 11:03

bendataclear


3 Answers

You have wrong spelling for html, hmlt should be html

Change

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

To

$("#basicperc").html(discountlist[elementname] + "%");
like image 104
Adil Avatar answered Oct 04 '22 02:10

Adil


you have a typo

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

should be

$("#basicperc").html(discountlist[elementname] + "%");
like image 44
bipen Avatar answered Oct 04 '22 01:10

bipen


you've made a typo, it's html not hmtl :)

like image 28
Mattyod Avatar answered Oct 04 '22 02:10

Mattyod