Forum Moderators: open

Message Too Old, No Replies

passing javascript value to html input

T_t

         

nanat

5:36 am on Jul 9, 2009 (gmt 0)

10+ Year Member



iam noobie from JavaScript i really need help..
how can i pass my variable js "C" to html form <input type="text" id="result" name="C" readonly="readonly"/>

T_T


<html>
<head>
<script type="text/javascript">
function upperCase()
{
var A = document.getElementById('input').value;
var B = document.getElementById('inpit').value;

C = A * B
document.write(C);
}
</script>
</head>

<body>
input: <input type="text" id="input" name="input" />
<br />
input2: <input type="text" id="inpit" name="input" onchange="upperCase()" />
<br />
<input type="text" id="result" name="C" readonly="readonly"/>

</body>

</html>

gracias ^^

daveVk

6:36 am on Jul 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Replace

document.write(C);

with

document.getElementById('result').value = C;

nanat

7:51 am on Jul 9, 2009 (gmt 0)

10+ Year Member



tnx dave.. follow up question dave..

assuming 2 form how can i put it into array?


<html>
<head>
<script type="text/javascript">
function upperCase()
{
var A = document.getElementById('input').value;
var B = document.getElementById('inpit').value;

C = A * B
document.getElementById('result').value = C;
}

function upperCase2()
{
var A1 = document.getElementById('input').value;
var B2 = document.getElementById('inpit').value;

C2 = A1 * B2

document.getElementById('result').value = C2;

}
</script>
</head>

<body>
input: <input type="text" id="input" name="input" />
<br />
input2: <input type="text" id="inpit" name="input" onchange="upperCase()" />
<br />
<input type="text" id="result" name="C" readonly="readonly"/>
<br /><br />

input3: <input type="text" id="input1" name="input1" />
<br />
input4: <input type="text" id="inpit2" name="inpit2" onchange="upperCase2()" />
<br />
<input type="text" id="result" name="C2" readonly="readonly"/>
</body>

</html>

gracias ^^ i hate being a noob.. 2 times work harder to understand T_T

daveVk

8:08 am on Jul 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<html>
<head>
<script type="text/javascript">
function upperCase(n)
{
var A = document.getElementById('input'+n).value;
var B = document.getElementById('inpit'+n).value;
document.getElementById('result'+n).value = A*B;
}

</script>
</head>

<body>
input: <input type="text" id="input1" name="input1" />
<br />
input2: <input type="text" id="inpit1" name="inpit1" onchange="upperCase(1)" />
<br />
<input type="text" id="result1" name="C1" readonly="readonly"/>
<br /><br />

input3: <input type="text" id="input2" name="input2" />
<br />
input4: <input type="text" id="inpit2" name="inpit2" onchange="upperCase(2)" />
<br />
<input type="text" id="result2" name="C2" readonly="readonly"/>
</body>

</html>

nanat

9:41 am on Jul 9, 2009 (gmt 0)

10+ Year Member



wow! pretty clever codes.. tnx dave

dave last quetion plz.. :D how can u add output1 + output2..
with the same label?

daveVk

1:17 pm on Jul 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not clear what you are asking, do you need the grand total C1+C2 put somewhere ? Or do I misunderstand ?

nanat

12:23 am on Jul 10, 2009 (gmt 0)

10+ Year Member



yes dave total C1+C2.. i think i need an array? i dont have anyidea to solve it.. help me dave

tnx..

daveVk

12:49 am on Jul 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<html>
<head>
<script type="text/javascript">
function upperCase(n)
{
var A = document.getElementById('input'+n).value;
var B = document.getElementById('inpit'+n).value;
document.getElementById('result'+n).value = A*B;

document.getElementById('total').value
= document.getElementById('result1').value;
+ document.getElementById('result2').value;

}
}

</script>
</head>

<body>
input: <input type="text" id="input1" name="input1 onchange="upperCase(1)"/>
<br />
input2: <input type="text" id="inpit1" name="inpit1" onchange="upperCase(1)" />
<br />
<input type="text" id="result1" name="C1" readonly="readonly"/>
<br /><br />

input3: <input type="text" id="input2" name="input2" onchange="upperCase(2)"/>
<br />
input4: <input type="text" id="inpit2" name="inpit2" onchange="upperCase(2)" />
<br />
<input type="text" id="result2" name="C2" readonly="readonly"/>

<br />
<input type="text" id="total" name="total" readonly="readonly"/>

</body>

</html>

nanat

1:09 am on Jul 10, 2009 (gmt 0)

10+ Year Member



dave its doesnt work the result is just like result1 = total

i think this statement argue because of the (;) ?

document.getElementById('total').value
= document.getElementById('result1').value
+ document.getElementById('result2').value

1*1 = 1, 1*1 = 1, sum is 1+1=11..

nanat

1:38 am on Jul 10, 2009 (gmt 0)

10+ Year Member



i sold it dave thank u very much for your help ^^

var A = document.getElementById('input'+n).value;
var B = document.getElementById('inpit'+n).value;
document.getElementById('result'+n).value = A*B;

document.getElementById('total').value
= (document.getElementById('result1').value-0)
+ (document.getElementById('result2').value-0)

:bow: :bow:

daveVk

1:45 am on Jul 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try

document.getElementById('total').value
= parseFloat( document.getElementById('result1').value )
+ parseFloat( document.getElementById('result2').value );