0

This is my function

function  doMath() { 
   var counter; var nvalue; var amount;
   var price=100;
   nValue = document.getElementById("message").value;
   amount=(nvalue*price);
   document.getElementById("total").value=amount ;
}

My html

<input type="" name="message" id="message" onkeyup="doMath()"maxlength="60">message
<input type="text" name="total" id="total" maxlength="60"> amount

when user enter value into message field it should calculate the amount automatically and show it in amount field.

but while i entering the value it show NAN

its not calculating can anyone help me how to fix this .i m new to javascript

3
  • 4
    You have some inconsistencies with your variable names... nvalue --> nValue. Variable names are case sensitive. Commented Sep 16, 2012 at 12:23
  • 1
    No problem, you can delete your question since that's all it was. Commented Sep 16, 2012 at 12:38
  • For javascript development I suggest using firebug and javascript debugger. It would immediately tell you, that nvalue is undefined. Commented Sep 16, 2012 at 12:50

2 Answers 2

2

You declared your variable as nvalue but used nValue instead.

   function  doMath() { 
       var nValue; var amount;
       var price=100;
       nValue = document.getElementById("message").value;
       amount=(nValue*price);
       document.getElementById("total").value=amount ;
    }
Sign up to request clarification or add additional context in comments.

Comments

1

Your error is here:

  amount = (nvalue * price);

It should be:

  amount = (nValue * price);

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.