Forum : Variable
Brief description  about Online courses   join in Online courses
View ganesh  pradhan 's Profile

Variable

I have pested below code,its not coming output where I have did mistake pls sought out this issued.


<html>
<head>
<title>
Setting up variables in JavaScript
</title>


<SCRIPT Language = JavaScript>



A = 500
B = 1500
C = B A
alert(C)


function calculate() {
A = document.frmOne.txtFirstNumber.value
B = document.frmOne.txtSecondNumber.value
C = (A B)
document.frmOne.txtThirdNumber.value = C;
}



function calculate() {
A = document.frmOne.txtFirstNumber.value
B = document.frmOne.txtSecondNumber.value
C = document.frmOne.txtThirdNumber.value
D = (A * B) C / 100
document.frmOne.txtFourthNumber.value = D;
}



</script>

<body>

<FORM NAME = frmOne>

Number One: <INPUT TYPE = Text NAME = txtFirstNumber SIZE = 5 value ="">

Number Two: <INPUT TYPE = Text NAME = txtSecondNumber SIZE = 5 value ="">
<P>
Total: <INPUT TYPE = Text NAME = txtThirdNumber SIZE = 5 value = "">
<P>
<Input Type = Button NAME = b1 VALUE = "Add Numbers" onClick = calculate()>

<p>





Number One: <INPUT TYPE = Text NAME = txtFirstNumber SIZE = 5 value ="">

Number Two: <INPUT TYPE = Text NAME = txtSecondNumber SIZE = 5 value ="">

Number Three: <INPUT TYPE = Text NAME = txtThirdNumber SIZE = 5 value ="">

<P>
Total: <INPUT TYPE = Text NAME = txtFourthNumber SIZE = 5 value = "">
<P>
<Input Type = Button NAME = b1 VALUE = "Add Numbers" onClick = calculate()>

</FORM>



</body>





</head>

</html>


Asked by ganesh pradhan | Aug 25, 2010 |  Reply now
Replies (5)
View ganesh pradhan 's Profile
Hi Arun I am not a engeenering student actually my basic for this i am a very new for javascript. Pls co-operate me i am relly oblige you.

Thanks you thanks a lot
Aug 25, 2010
View ganesh pradhan 's Profile
Thanks K Arun G for your co-operate,your giving me (eg:A=parseInt)This eg is very new for me first time iam doing with this method.
Aug 25, 2010
View anonymous anonymouse 's Profile
javascript is a interpreter language ,so you need to use different names for element.
txtFirstNumber..txtFirstNumber1,txtSecondNumber1...

<html>
<head>
<title>
Setting up variables in JavaScript
</title>


<SCRIPT type = "text/JavaScript"> //language="javascript" it is outdated //and should be considered as poor coding practice.

A = 500;
B = 1500;
C = B+A;
alert(C);



function calculate() {
A = parseInt(document.frmOne.txtFirstNumber.value);
B = parseInt(document.frmOne.txtSecondNumber.value);
C = A+ B
document.frmOne.txtThirdNumber.value=C;

}

//parseInt(document.getElementById("value1").value);

function calculate1() {
A = parseInt(document.frmOne.txtFirstNumber1.value);
B = parseInt(document.frmOne.txtSecondNumber1.value);
C = parseInt(document.frmOne.txtThirdNumber1.value);
D = ((A * B)* C )/ 100
document.frmOne.txtFourthNumber.value = D;
}
</script>

<body>

<FORM NAME = frmOne>

Number One: <INPUT TYPE = Text NAME = txtFirstNumber SIZE = 5 value =""> <br /><br />

Number Two: <INPUT TYPE = Text NAME = txtSecondNumber SIZE = 5 value ="">
<P>

Total: <INPUT TYPE = Text NAME = txtThirdNumber SIZE = 5 value = What?>
<p>
<Input Type = Button NAME = b1 VALUE = "Add Numbers" onClick = "calculate();">

<br /><br />
Number One: <INPUT TYPE = Text NAME = txtFirstNumber1 SIZE = 5 value ="">
<br /><br />
Number Two: <INPUT TYPE = Text NAME = txtSecondNumber1 SIZE = 5 value ="">
<br /><br />
Number Three: <INPUT TYPE = Text NAME = txtThirdNumber1 SIZE = 5 value ="">

<P>
Total: <INPUT TYPE = Text NAME = txtFourthNumber SIZE = 5 value = "aha">
<P>
<Input Type = Button NAME = b1 VALUE = "Add Numbers" onClick = "calculate1();">

</FORM>
</body>
</head>
</html>

Aug 25, 2010
View anonymous anonymouse 's Profile
1) How can u add two String or Are doing concatenation.??

2)if you are adding numbers use parseInt() method

eg: A = parseInt(document.frmOne.txtFirstNumber.value)
B = parseInt(document.frmOne.txtSecondNumber.value)
C = A+ B
Aug 25, 2010
View anonymous anonymouse 's Profile
What are you trying to do?
Aug 25, 2010