42 users online (1 members and 41 guests)  


  Results 1 to 3 of 3

Related

  1. html css element alignment    Forum: CSS Forum
    Replies: 5
  2. How to use getElementById with a body element    Forum: Javascript Forum
    Replies: 4
  3. Load page into HTML element    Forum: Javascript Forum
    Replies: 1
  4. Replies: 1
  1. #1
    rhyspaterson's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    1

    Mutiple element id's

    Hey guys,

    Just wondering if it is possible to return the value of multiple elements in one command? If that didn't make sense, which it probably doesn't because i'm an idiot, here is an example:

    Original code is

    Code:
    var aText = document.getElementById('textarea1').value;

    Which works nicely, but looking to return the value of three -
    Code:
    var aText = document.getElementById('textarea1', 'textarea2', 'textarea3').value;


    Which doesn't work obviously. Just not sure how to do it, heh. Any help would be muchly appreciated! Thanks guys http://www.webdeveloper.com/forum/im...lies/smile.gif

  2. #2
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Mutiple element id's

    I'm not a JavaScript user, but you'd need the JavaScript equivalant of :
    Code:
    var aText = var aText = concatenate(document.getElementById('textarea1').value, document.getElementById('textarea2').value, document.getElementById('textarea3').value);

  3. #3
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: Mutiple element id's

    Hi there rhyspaterson,

    and a warm welcome to these forums.

    Does this help the cause in any way...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script type="text/javascript">
       var aText=new Array();
       var inp=document.getElementsByTagName('input');
    window.onload=function() {
    for(c=0;c<inp.length;c++) {
       aText[c]=document.getElementById('textarea'+(c+1)).value;
    }
    alert(aText);
    }
    </script>
    
    </head>
    <body>
    
    <form action="#">
    <div>
    <input id="textarea1" value="fee"/>
    <input id="textarea2" value="fie"/>
    <input id="textarea3" value="foe"/>
    <input id="textarea4" value="fum"/>
    </div>
    </form>
    
    </body>
    </html>



Tags for this Thread