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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to I change value of dynamic form field when checkbox is checked? 1

Status
Not open for further replies.

LyndonOHRC

Programmer
Sep 8, 2005
603
US
I have a form with a dynamic number of text fields, each field has checkboxes under them. I want to change the value of the text field when the box is checked.

I'm missing something. the_field.value='100' is not giving an error, but is not referencing the field either.

Need help
Thanks

Code:
<form name="Receipt" action="PrintReceipt" method="post">
	
	<input name="Amount#i#" type="Text" size="5">
	<input name="CBoxA" value="1" type="Checkbox" onclick="CBoxA('#i#')">


<script language="JavaScript" type="text/javascript">
function AmountA(i){
	var the_field='document.Receipt.Amount'+i;
	the_field.value='100';
}
</script>

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
You're using the quotes incorrectly. Try this
Code:
function AmountA(i)
{
document.forms['Receipt'].elements['Amount'+i].value='100';
}

You could have done an eval on the string you built, but there's no point of messing around with that when there's a simpler way.

Lee
 
Thanks Lee!!

Works like a charm.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top