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

Accessing form field dynamically

Status
Not open for further replies.

arunjp

Programmer
Jan 10, 2001
29
US
Hi !
I've created a form where all the textfields are created dynamically based on the records available on the database. So the name of the field is also assigned dynamically (from jsp ). I want to disable the field based on a condition. So in each text field, I wrote a event function like this :

<INPUT TYPE=&quot;text&quot; NAME=&quot;txt0<%= i %>0&quot; VALUE=&quot;<%= rs_partdetail.getLong(13) %>&quot; SIZE=&quot;8&quot; MAXLENGTH=&quot;13&quot; onFocus=&quot;fnDisable(this.form, this.name);&quot;>

And in the function, I try to disable that particulatr field calling this function by :

function fnDisable(frmname, fieldname)
{
if(multiFlag == &quot;N&quot;)
{
alert(document.frmname.fieldname.value);
return false;
}
}

But I get error an error saying that
&quot;document.frmname has no properties.&quot;
The catch is disable should work in both the browsers. What could be the problem. How to refer to the form field that has dynamic name.

Thanx
AJP
 
because you are passing this.form, the document reference is already included in that, so your code is trying:

document.document.formname

change your cuntion to look like this:

function fnDisable(frmname, fieldname)
{
if(multiFlag == &quot;N&quot;)
{
alert(frmname.fieldname.value);
return false;
}
}

and it should do as you intended jared@aauser.com
 
Hi !
I tried that also. But still I get the following error.

&quot;frmname.fieldname has no properties.&quot; in Netscape.

Could u help me out in this.

Thanx
AJP
 
just pass this to it then:

function fnDisable(obj)
{
if(multiFlag == &quot;N&quot;)
{
alert(obj.value);
return false;
}
}
jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top