[thelist] JS: referencing a variable form element

Joe Crawford joe at artlung.com
Tue Jun 29 16:26:41 CDT 2004


On Tue, 29 Jun 2004, Tab Alleman wrote:
> 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;

//I think your syntax here should be:
       var ThisForm = document[TheFormName];
       var QuantityField = ThisForm[TheFieldName];
       var TestValue = QuantityField.value;

> 	alert(TestValue);
> 	return true;
> 	}

Try that. The thing is to have the strings evaluated as object names.

Best,
	Joe
--
Joe "ArtLung" Crawford   AIM:artlung   Phone:619-516-4550
LAMP Host Evangelist, Web Designer, Web Developer, WebSanDiego.org List Guy
http://joecrawford.com/  http://lamphost.net/  http://artlung.com/
http://artlung.com/blog/  http://sandiegobloggers.com/
http://sandiegoblog.com/  http://websandiego.org/



More information about the thelist mailing list