5

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>
2
  • 3
    It's .html(), not .hmtl(). Commented Mar 27, 2013 at 11:28
  • Wow, thanks guys, embarrassing! Commented Mar 27, 2013 at 11:33

4 Answers 4

4

You have wrong spelling for html, hmlt should be html

Change

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

To

$("#basicperc").html(discountlist[elementname] + "%");
Sign up to request clarification or add additional context in comments.

Comments

4

you have a typo

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

should be

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

Comments

4

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

Comments

3

Very obvious typo. It's html, not hmtl !

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.