Greetings! I'm just a new student in javascript. I have an assignment to add the following values but I don't know how. Let me show you first my code. JS You noticed that there are two select option tag in the html file that is an array. Can you help me how to add the two tags whenever I click the calculate button using JS or jQuery? I tried my best to do it but no luck. It just gives me 'NaN' alert return when ever I click the calculate button. I hope you can help me guys.
Are you required to use jQuery here? (You're shooting a flea with an atomic bomb.) Javascript itself is powerful enough to add 2 numbers. Use something of the form of var discount = parseInt($(".discount").val()); if you have to use jQuery. "15" isn't a number, it's characters. $(".discount").val() is the characters in the thing with the class discount, not the numeric value.
try this <script type="text/javascript"> $(document).ready(function(){ $("#calc").click(function(){ var total = 0; $(".discount\\[\\]").each(function(){ total += $(this).val()*1; }); alert(total); }); }); </script> HTML: