Jump to content

Data type


Namal
 Share

Recommended Posts

In my Html document, I created 3 input boxes. Those (ID s)are txt1txt2txttotIn my javascript document, I have 2 variables. Those arevar tmp;var total;I created a function like this....(javascript)function totval(){tmp= document.getElementById('txt1').value + document.getElementById('txt2').value;total=tmp;document.getElementById('txttot').value= tmp;}---------------------------------------------Html document<input type="text" id="txt1" ><input type="text" id="txt2" ><input type="text" id="txttot"><input type="button" onClick="totval()" value="Total"/> This is my problem.... In running mode, I will insert 25 and 50 to 'txt1' and 'txt2' textboxes.Accordion to my function, the value of 'tmp' should be= 75.but the value was display tmp= 2550How to get my expected value??

Link to comment
Share on other sites

Replace this:tmp= document.getElementById('txt1').value + document.getElementById('txt2').value;With this:tmp= eval("document.getElementById('txt1').value + document.getElementById('txt2').value")

Link to comment
Share on other sites

Replace this:tmp= document.getElementById('txt1').value + document.getElementById('txt2').value;With this:tmp= eval("document.getElementById('txt1').value + document.getElementById('txt2').value")
:):) Thank you very much for your reply. My function is working now.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...