naming a form element with a variable?

Discussion in 'Javascript' started by libsfan01, Jul 23, 2006.

  1. libsfan01

    libsfan01 Guest

    what am i doing wrong here, im trying to name a field to add a value
    to in a form by use of a variable?

    var field = 'content'; //field name is content
    document.update.field.value = string;
     
    libsfan01, Jul 23, 2006
    #1
    1. Advertising

  2. libsfan01

    Randy Webb Guest

    libsfan01 said the following on 7/23/2006 8:41 AM:
    > what am i doing wrong here, im trying to name a field to add a value
    > to in a form by use of a variable?
    >
    > var field = 'content'; //field name is content
    > document.update.field.value = string;


    document.forms['update'].elements[field].value

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Jul 23, 2006
    #2
    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. Rod  Snyder

    moving from form element to form element

    Rod Snyder, May 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    410
    Vidar Petursson
    May 29, 2004
  2. Replies:
    0
    Views:
    595
  3. Harman
    Replies:
    1
    Views:
    2,518
    Moiristo
    Jul 28, 2006
  4. William Holroyd

    Accessing form element with non-conventional naming

    William Holroyd, Jun 15, 2004, in forum: Javascript
    Replies:
    1
    Views:
    102
    Richard Cornford
    Jun 15, 2004
  5. Duncan Harris
    Replies:
    7
    Views:
    116
    Anno Siegel
    Feb 13, 2005
Loading...

Share This Page