0

sir i have 7 text boxes .1st two take values from user and display the multiplication result on 3rd text box when it clicked.4th and 5th textboxes also take values and display the multiplication result in 6th text box when it clicked.now 7th textbox will display the addition result when it clicked.7th textbox takes the values from 3rd and 6th textbox. my problem is that i can not do the addition and cant display the result in 7th text box in html and jscript.plz help me.....i am attached the code...

 <html> <script> function getText1(){ var in1=document.getElementById('in1').value; var in2=document.getElementById('in2').value; var tot1=parseInt(in1)*parseInt(in2); document.getElementById('tot1').value=tot1; } function getText2(){ var in1=document.getElementById('in3').value; var in2=document.getElementById('in4').value; var tot2=parseInt(in1)*parseInt(in2); document.getElementById('tot2').value=tot2; } function gt1(){ var in1=document.getElementById('tot1').value; var in2=document.getElementById('tot2').value; var gt1=parseInt(in1)+parseInt(in2); document.getElementById('gt').value = gt1; </script> <form> <input type="text"id="in1"/> <input type="text" id="in2"/> <input type="text" onclick="getText1()" id="tot1"/> <br> <input type="text"id="in3"/> <input type="text" id="in4"/> <input type="text" onclick="getText2()" id="tot2"/> <br> <input type="text" onclick="gt1()" id="gt1"/> </form> </html> 
4
  • It has to be document.getElementById('gt1').value=gt1; (gt1 instead of gt). Commented Sep 16, 2014 at 8:39
  • bt still not working...plz help Commented Sep 16, 2014 at 8:43
  • some one plz help me.... Commented Sep 16, 2014 at 8:50
  • relplace this code document.getElementById('gt1').value = gt1; Commented Sep 16, 2014 at 9:17

5 Answers 5

1
<html> <script> function getText1(){ var in1=document.getElementById('in1').value; var in2=document.getElementById('in2').value; var tot1=parseInt(in1)*parseInt(in2); document.getElementById('tot1').value=tot1; } function getText2(){ var in1=document.getElementById('in3').value; var in2=document.getElementById('in4').value; var tot2=parseInt(in1)*parseInt(in2); document.getElementById('tot2').value=tot2; } function gt(){ var in1=document.getElementById('tot1').value; var in2=document.getElementById('tot2').value; var gt1=parseInt(in1)+parseInt(in2); document.getElementById('gt1').value = gt1; } </script> <form> <input type="text"id="in1"/> <input type="text" id="in2"/> <input type="text" onclick="getText1()" id="tot1"/> <br> <input type="text"id="in3"/> <input type="text" id="in4"/> <input type="text" onclick="getText2()" id="tot2"/> <br> <input type="text" onclick="gt()" id="gt1"/> </form> </html> 

use this code it is working. and compare with own code. thanks..

Sign up to request clarification or add additional context in comments.

Comments

1

There are several problem

1). Element id is one line is incorrect. It should be:

document.getElementById('gt1').value = gt1; 

2). result variable is undefined. It should be:

if (!isNaN(gt1)) 

3). onclick="gt1()" will not work (because there is id with the same name gt1). Use, for example:

function getText3() { ... } 

and

<input type="text" onclick="getText3()" id="gt1"/> 

Fiddle.

Update. Ok, I didn't notice that you want multiplication, but somewhy had written + in getText1() and getText2() functions. Then you should also replace these two + with *:

Multiplication fiddle.

1 Comment

@ArghaGuhaRoy if by "not working" you were talking about replacing + with * - I have done this in updated fiddle.
0

You dont have element with id 'gt'.

Change last line of code to this:

document.getElementById('gt1').value = gt1; 

2 Comments

@ArghaGuhaRoy check 'Regent' answer also. Rename your gt1 function.
@aleha by the way, I'm still suprised that gt1 function will not be excuted when there is id="gt1"
0

You have not defined 'result' variable and in 'gt1()' :

document.getElementById('gt').value = gt1; 

1- There is no 'gt' element in the page

2- 'gt1' should renamed to 'result' and at the end code will be:

<script language="javascript" type="text/javascript"> function getText1() { var in1 = document.getElementById('in1').value; var in2 = document.getElementById('in2').value; var tot1 = parseInt(in1) + parseInt(in2); document.getElementById('tot1').value = tot1; } function getText2() { var in1 = document.getElementById('in3').value; var in2 = document.getElementById('in4').value; var tot2 = parseInt(in1) + parseInt(in2); document.getElementById('tot2').value = tot2; } function gt1() { var in1 = document.getElementById('tot1').value; var in2 = document.getElementById('tot2').value; var result = parseInt(in1) + parseInt(in2); if (!isNaN(result)) { document.getElementById('gt1').value = result; } //document.getElementById('gt1').value=gt1; } </script> 

this is work properly.

Comments

0

Check the below code.

<script > function getext3(){ txt1 = document.getElementById("text1").value; txt2 = document.getElementById("text2").value; document.getElementById("text3").value = parseInt(txt1)*parseInt(txt2); } function getext6(){ txt1 = document.getElementById("text4").value; txt2 = document.getElementById("text5").value; document.getElementById("text6").value = parseInt(txt1)*parseInt(txt2); } function getext7(){ txt1 = document.getElementById("text3").value; txt2 = document.getElementById("text6").value; document.getElementById("text7").value = parseInt(txt1)+parseInt(txt2); } </script> Text1 : <input type="text" id="text1" value="5"> <br/> Text2 : <input type="text" id="text2" value="2"> <br/> Text3 : <input type="text" id="text3" value="" onclick="getext3()"> <br/> Text4 : <input type="text" id="text4" value="7"> <br/> Text5 : <input type="text" id="text5" value="10"> <br/> Text6 : <input type="text" id="text6" value="" onclick="getext6()"> <br/> Text7 : <input type="text" id="text7" value="" onclick="getext7()"> <br/> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.