Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    1
    Thanks
    0
    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
    Location
    London, England
    Posts
    18,016
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    I am not too clear as to what you are trying to achieve, but this may help you:-

    Code:
    <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;
    </script>

    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
    •