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!

How to refer to DHTML objects using a variable name

Status
Not open for further replies.

PGTips2

Programmer
Jul 25, 2001
2
GB
This one has me stumped and I hope someone knows the answer.

I am reading a number of records from a database and building up a list of products on an ASP Page.

As the code that generates each line of the list is in a Server Side loop I am naming each field using the ID of the record from the database:

IE:
<Input type &quot;Checkbox&quot; name=&quot;Instock1&quot;>
<Input type &quot;Checkbox&quot; name=&quot;Instock2&quot;>
<Input type &quot;Checkbox&quot; name=&quot;Instock3&quot;>

I have a link on each line that calls a client side VBScript function to dynamically check this box. It passes the ID to the function so it knows which one to check.

A part of my function looks like this

Function CheckBox(intRecordID)
strObjectName=&quot;InStock&quot; & intRecordID
...
End Function

So I have a variable that contains the name of the object I want to check but the line:
frm.strObjectName=Checked

doesn't work.

How do I tell the browser to look at the object whose name is contained within the string strObjectName?

I've looked everywhere for some kind of conversion/eval function but with no success.

Anyone know how to do it?

Paul Garden
 
eval(strObjectName) or else it doesn't find it's a variable ------
please review FAQ183-874 - this will help you to get the best out of tt
[ &quot;you&quot; is not someone in particular - don't take it too personnal ]
 
I'm not sure that -

eval(strObjectName)

will work, but I do know that if your clients have IE 5 or higher, you can use this -

Function CheckBox(intRecordID)
strObjectName=&quot;InStock&quot; & intRecordID
Execute &quot;frm.&quot; & strObjectName & &quot;.checked = true&quot;
...
End Function


but if they don't necessarily have IE 5, then you can put an inline script with each button if that is possible... &quot;A computer scientist is a person who knows when it is time to hit the computer.&quot;

John

johnmc@mvmills.com
 
hey Paul, which was the working solution ?? the eval() or the execute() one ?? ------
please review FAQ183-874 - this will help you to get the best out of tt
[ &quot;you&quot; is not someone in particular - don't take it too personnal ]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top