[thelist] JS: referencing a variable form element

Tab Alleman Tab.Alleman at MetroGuide.com
Tue Jun 29 15:51:35 CDT 2004


I want to pass the name of a form element to a JS function and get its
value, but am getting a "not an object" error.

My function (so far):

function TestMaxQuantity(TheFormName, TheFieldName, TheMaxQuantity)
	{
	var ThisForm = document.TheFormName;
	var QuantityField = ThisForm.TheFieldName;
	var TestValue = QuantityField.value;
	alert(TestValue);
	return true;
	}

My form:

<form action="ShopAddToCart.asp" method="POST"
name="AddToCart_Product_52" onSubmit="return
TestMaxQuantity('AddToCart_Product_52', 'quantity', '4');">
<input type='text' maxlength=4 size='3' value='1' name='quantity'>
<input border=0 src=/img/DC_but_continue.gif type=image>
<input type="hidden" name="productid" value="52">
</form>
 
When I submit the form, I get "Error:  'TheFieldName' is null or not an
object."

What am I doing wrong?


More information about the thelist mailing list