Acces Objects Using String Variable: Is it Possible?

Discussion in 'Javascript' started by Himaxda0, Feb 29, 2004.

  1. Himaxda0

    Himaxda0 Guest

    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..
     
    Himaxda0, Feb 29, 2004
    #1
    1. Advertising

  2. Himaxda0

    Ryan Stewart Guest

    "Himaxda0" <> wrote in message
    news:...
    > 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/
     
    Ryan Stewart, Feb 29, 2004
    #2
    1. Advertising

  3. (Himaxda0) writes:

    > 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
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Feb 29, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWxleCBGaW1pbmU=?=

    One or multiple command objects for ASP.NET app to MSSQL (or Acces

    =?Utf-8?B?QWxleCBGaW1pbmU=?=, Sep 11, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    450
    Cor Ligthert
    Sep 11, 2004
  2. Anthony
    Replies:
    6
    Views:
    387
    Michel de Becdelièvre
    Sep 23, 2003
  3. silversurfer2025
    Replies:
    16
    Views:
    531
    silversurfer2025
    Jul 24, 2006
  4. 001
    Replies:
    1
    Views:
    307
    Daniel Pitts
    Mar 28, 2007
  5. Yevgen Reznichenko

    Unable to acces "$?" environment variable

    Yevgen Reznichenko, Nov 1, 2003, in forum: Perl Misc
    Replies:
    5
    Views:
    99
    Yevgen Reznichenko
    Nov 1, 2003
Loading...

Share This Page