Namal Posted December 26, 2006 Share Posted December 26, 2006 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 More sharing options...
Chocolate570 Posted December 26, 2006 Share Posted December 26, 2006 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 More sharing options...
Namal Posted December 27, 2006 Author Share Posted December 27, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now