Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Thanked 0 Times in 0 Posts

    Beginner --> Appending string to DOM document.form.input(appendhere).value

    Hi all,

    I'm new to Javascript, and having a little trouble figuring out how to append strings to DOM assignments.

    To be specific:

    var appendhere = 'firstfield';
    document.form.input(want to put 'appendhere' in here).value = myvalue;

    I want to be read as "document.form.inputfirstfield.value". I'm guessing there's a simple solution for this, but unfortunately google doesn't seem to be of any help. "input+appendhere" outputs literally as document.form.input+appendhere.value.

    Any help appreciated - many thanks.

    - SuperGrover

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,565 Times in 2,543 Posts
    I am not too clear as to what you are trying to achieve, but this may help you:-

    <input type = "text" name = "inputfirstfield" id = "inputfirstfield">
    <script type = "text/javascript">
    var myvalue = "abcdefgh";
    var appendhere = 'firstfield';
    var x = "input"+ appendhere;
    document.getElementById(x).value = myvalue;

    Q. If you were to spell out numbers, how far would you have to go until you would find the letter "A"?
    A. One thousand


    Posting Permissions

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