www.webdeveloper.com
Results 1 to 6 of 6

Thread: Simple TextBox question

  1. #1
    Join Date
    Oct 2007
    Posts
    3

    Simple TextBox question

    I'm trying to use a variable to write to a textbox and I can't seem to nail the syntax. I've tried searching but I couldn't find anything (probably because I don't know what exactly to search for).

    document.fast.textbox1.value=23;
    works fine.

    however,
    variable = textbox1;
    document.fast.variable.value=23;
    does not.

    I've tried several different variations of adding braces, brackets and quotes, but I can't seem to nail it. I'm using JavaScript to auto populate textBoxes in a PHP form. My JavaScript knowledge is extremely limited.

    Thanks for your help

    -Kevin

  2. #2
    Join Date
    Jul 2005
    Location
    USA
    Posts
    3,910
    Welcome to WebDeveloper.com Forums, Kevin.

    Perhaps this will help.
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions

    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

    Check out my blog.

  3. #3
    Join Date
    Oct 2007
    Posts
    3
    I've read that entire page and I've tried everything I can think of.
    I just can't seem to get the function to populate the textBox using a variable.
    Do you have any other suggestions or code to try?

    Thanks again for your help
    -Kevin

  4. #4
    Join Date
    Jul 2005
    Location
    USA
    Posts
    3,910
    This is what that page showed applied to your example:
    Code:
    variable = 'textbox1';
    document.fast.elements[variable].value=23;
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions

    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

    Check out my blog.

  5. #5
    Join Date
    Oct 2007
    Posts
    3
    That was it - I can't thank you enough.

    I was trying getElementsByID[variable] and getElementsByName[variable]

    Thanks again
    -Kevin

  6. #6
    Join Date
    Jul 2005
    Location
    USA
    Posts
    3,910
    You're welcome

    There is no getElementsByID. Since IDs should be uniquely applied to one element in a document.

    getElementByID() (singular) and getElementsByName() are methods of document and use parentheses, not array notation brackets the way arrays and NodeLists do.
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions

    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

    Check out my blog.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles