Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Value Change from Several Input Text Boxes

Status
Not open for further replies.

sandra45

Technical User
Apr 3, 2003
72
0
0
ID
Hi, I want to change value of one input text box based on values changed from several input text boxes, can this be done? Let's say box A=8, if box B is changed to 1, value in box A=(8-1=7), and if box C is changed to 2, value in box A=(7-2=5) and so on.

Can anyone tell me how to do this? Thanks.

Regards,
Sandra

 
This is one possibility:
Code:
<form>
A:<input type="text" name="A" value="8"><br>
B:<input type="text" name="B" value="0" onchange="setA(this)"><br>
C:<input type="text" name="C" value="0" onchange="setA(this)"><br>
</form>

<script language="javascript">
function setA( oFld )
{	oForm = oFld.form;
	oForm["A"].value = parseInt(oForm["A"].value) - parseInt(oFld.value);
}
</script>
... and another one:
Code:
<form>
A:<input type="text" name="A" value="8"><br>
B:<input type="text" name="B" value="0"><br>
C:<input type="text" name="C" value="0"><br>
<input type="button" value="Change" onclick="setA( this.form )">
</form>

<script language="javascript">
function setA( oForm )
{	var B = parseInt( oForm["B"].value);
	var C = parseInt( oForm["C"].value);

	oForm["A"].value = parseInt(oForm["A"].value) - B - C;
}
</script>
 
Hi, thanks a lot, it works great!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top