By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,480 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,480 IT Pros & Developers. It's quick & easy.

how to get value from element

P: 77
i have this script...

Expand|Select|Wrap|Line Numbers
  1.             var td = document.createElement('td');
  2.             var p = document.createElement('p');
  3.             var label = document.createElement('label');
  4.             var span = document.createElement('span');
  5.             var theData = document.createTextNode(pbdcuraian);
  6.             var theTextarea = document.createElement('textarea');
  7.             theTextarea.setAttribute('name', 'items['+item_count+'][work_description]');
  8.             theTextarea.setAttribute('id', 'items['+item_count+'][work_description]');
  9.             theTextarea.setAttribute('rows', '2');
  10.             theTextarea.setAttribute('cols', '25');
  11.             label.appendChild(span);
  12.             theTextarea.appendChild(theData);
  13.             label.appendChild(theTextarea);
  14.             p.appendChild(label);
  15.             td.appendChild(p);
  16.             row.appendChild(td);
  17.  
  18.             var td = document.createElement('td');
  19.             var p = document.createElement('p');
  20.             var label = document.createElement('label');
  21.             var span = document.createElement('span');
  22.             var theData = document.createTextNode('Location');
  23.             var theInput = document.createElement('input');
  24.             theInput.setAttribute('type', 'text');
  25.             theInput.setAttribute('name', 'items['+item_count+'][pbdckdlok]');
  26.             theInput.setAttribute('size', '3');        
  27.             theInput.setAttribute('value',pbdckdlok);
  28.             span.appendChild(theData);
  29.             label.appendChild(span);
  30.             label.appendChild(theInput);
  31.             p.appendChild(label);            
  32.             td.appendChild(p);
  33.             row.appendChild(td);
  34.  
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??
Jul 23 '08 #1
Share this Question
Share on Google+
3 Replies


P: 57
You need to access the value element of the object
Expand|Select|Wrap|Line Numbers
  1. theTextArea.value
  2.  
Jul 23 '08 #2

P: 77
You need to access the value element of the object
Expand|Select|Wrap|Line Numbers
  1. theTextArea.value
  2.  

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

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

idea??
Jul 23 '08 #3

gits
Expert Mod 5K+
P: 5,343
just get the list of input-elements with:

Expand|Select|Wrap|Line Numbers
  1. var list = document.getElementsByTagName('input'); 
  2.  
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:

Expand|Select|Wrap|Line Numbers
  1. var a = [];
  2.  
  3. for (var i = 0, n; n = id_list[i]; i++) {
  4.     a.push(document.getElementById(n).value);
  5. }
in this case a would have all values that correspond to the nodes with the stored ids in the list

kind regards
Jul 23 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.