SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get the value of a textarea?

    Hello,

    I've come across a minor problem in my work and it's driving me up the wall...

    I have 30 textarea filelds named thus:

    <textarea id="comment_reply1">this is sometext</textarea>
    ...
    <textarea id="comment_reply30">this is sometext</textarea>

    and i simply want to store the value of a particular one in a variable.

    I know that you can do a document.formName.elementName.value and get it, but the thing is, I'm not sure which element I'll be requiring in my post so I'd like to to use a variable in my value select.

    document.formName.elementName + number.value

    of course doesn't work... variables are not usable in such a case. I'm unable to select the value with an getElementBy('elementName' + number).value either (of course I'm adding the proper id to the element).

    How does one select the value of a textarea using a variable name such as "elementName" + number?

    One would think this would be very simple.

    Or am I just making it overly difficult?

    thanks,

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try indirect addressing syntax []:

    Code:
    document.forms.formName[elementName + number].value

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that'll do. thanks!


Bookmarks

Posting Permissions

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