how to get value from element

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maminx
    New Member
    • Jul 2008
    • 77

    #1

    how to get value from element

    i have this script...

    [CODE=javascript]
    var td = document.create Element('td');
    var p = document.create Element('p');
    var label = document.create Element('label' );
    var span = document.create Element('span') ;
    var theData = document.create TextNode(pbdcur aian);
    var theTextarea = document.create Element('textar ea');
    theTextarea.set Attribute('name ', 'items['+item_count+'][work_descriptio n]');
    theTextarea.set Attribute('id', 'items['+item_count+'][work_descriptio n]');
    theTextarea.set Attribute('rows ', '2');
    theTextarea.set Attribute('cols ', '25');
    label.appendChi ld(span);
    theTextarea.app endChild(theDat a);
    label.appendChi ld(theTextarea) ;
    p.appendChild(l abel);
    td.appendChild( p);
    row.appendChild (td);

    var td = document.create Element('td');
    var p = document.create Element('p');
    var label = document.create Element('label' );
    var span = document.create Element('span') ;
    var theData = document.create TextNode('Locat ion');
    var theInput = document.create Element('input' );
    theInput.setAtt ribute('type', 'text');
    theInput.setAtt ribute('name', 'items['+item_count+'][pbdckdlok]');
    theInput.setAtt ribute('size', '3');
    theInput.setAtt ribute('value', pbdckdlok);
    span.appendChil d(theData);
    label.appendChi ld(span);
    label.appendChi ld(theInput);
    p.appendChild(l abel);
    td.appendChild( p);
    row.appendChild (td);
    [/CODE]

    actually i have one element textarea and five element input (the script only show for one creation of element input).

    I want to get a value from those element, how can i get those value of elements, any idea??
    Last edited by gits; Jul 23 '08, 07:07 AM. Reason: added code tags
  • Brosert
    New Member
    • Jul 2008
    • 57

    #2
    You need to access the value element of the object
    Code:
    theTextArea.value

    Comment

    • maminx
      New Member
      • Jul 2008
      • 77

      #3
      Originally posted by Brosert
      You need to access the value element of the object
      Code:
      theTextArea.value

      yes of course, i know i can get the value with that script or this.getAttribu te('value')...

      but that's only works for one element input, and you know as i said i have 5 elements input...

      idea??

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        just get the list of input-elements with:

        [CODE=javascript]var list = document.getEle mentsByTagName( 'input');
        [/CODE]
        loop through the list and store the values the way you want ... you could even store the ids of the created nodes during the creation process and then loop over this ids and retrieve the values with:

        [CODE=javascript]var a = [];

        for (var i = 0, n; n = id_list[i]; i++) {
        a.push(document .getElementById (n).value);
        }[/CODE]
        in this case a would have all values that correspond to the nodes with the stored ids in the list

        kind regards

        Comment

        Working...