Acces Objects Using String Variable: Is it Possible?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Himaxda0

    Acces Objects Using String Variable: Is it Possible?

    Is it possible to access Objects like (document.form1 .textfield1) with
    a string variable like (var obName='textfie ld1') 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..
  • Lasse Reichstein Nielsen

    #2
    Re: Acces Objects Using String Variable: Is it Possible?

    himaxda0@yahoo. com (Himaxda0) writes:
    [color=blue]
    > Is it possible to access Objects like (document.form1 .textfield1) with
    > a string variable like (var obName='textfie ld1') and using
    > (document.form1 .obName.value)?[/color]

    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
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Ryan Stewart

      #3
      Re: Acces Objects Using String Variable: Is it Possible?

      "Himaxda0" <himaxda0@yahoo .com> wrote in message
      news:acb03a43.0 402281903.205f5 49c@posting.goo gle.com...[color=blue]
      > Is it possible to access Objects like (document.form1 .textfield1) with
      > a string variable like (var obName='textfie ld1') 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..[/color]

      See the FAQ which is posted here frequently or available here:



      Comment

      Working...