Acces Objects Using String Variable: Is it Possible?

H

Himaxda0

Is it possible to access Objects like (document.form1.textfield1) with
a string variable like (var obName='textfield1') and using
(document.form1.obName.value)?
Ive tried it in IE but the value in the obName is not cosidered as a
object name. Help PLZ..
 
R

Ryan Stewart

Himaxda0 said:
Is it possible to access Objects like (document.form1.textfield1) with
a string variable like (var obName='textfield1') and using
(document.form1.obName.value)?
Ive tried it in IE but the value in the obName is not cosidered as a
object name. Help PLZ..

See the FAQ which is posted here frequently or available here:
http://www.jibbering.com/faq/
 
L

Lasse Reichstein Nielsen

Is it possible to access Objects like (document.form1.textfield1) with
a string variable like (var obName='textfield1') and using
(document.form1.obName.value)?

Yes, except not like that. It's even in the FAQ:
<URL:http://jibbering.com/faq/index.html#FAQ4_39>

First of all, the safest way to access the form control is:
document.forms['form1'].elements['textfield1'].value
i.e., through the forms and elements collections. That also makes
it easier to access using a string or string variable:
document.forms['form1'].elements[obName].value


/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top