Posted By

davaodude on 03/29/07


Tagged

form input


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

vali29


Copy/repeat input form values


 / Published in: JavaScript
 

Copy values from the first row of a column down the entire column. This was used in a specific project, but the code could be helpful for other projects.

  1. function copyDown(nm) {
  2. // written by Daniel P 3/20/07
  3. // repeat the values of the first row of a column down the whole column
  4. // special case for sku: value in incremented as you go down.
  5. // also, values are only filled in for rows that have a sku filled in
  6. var lastskuindex = document.getElementById('lastindex');
  7. var firstitem = document.getElementById(nm+'0');
  8. z = firstitem.value;
  9. for ( i=1; i<=lastskuindex.value; i++ ) {
  10. //window.receivelist["Received"+i].checked=true;
  11. if (nm=='SKUCode' && z!='') { // special case for skucode (when not blank)
  12. z++; // increments the sku
  13. zstring = z.toString();
  14. if ( zstring.length == 1 ) zstring='00000'+zstring;
  15. if ( zstring.length == 2 ) zstring='0000'+zstring;
  16. if ( zstring.length == 3 ) zstring='000'+zstring;
  17. if ( zstring.length == 4 ) zstring='00'+zstring;
  18. if ( zstring.length == 5 ) zstring='0'+zstring;
  19. document.getElementById(nm+i).value = zstring;
  20. } else {
  21. if (document.getElementById('SKUCode'+i)) { // if there's an editable skucode (only add page)
  22. if (document.getElementById('SKUCode'+i).value != '') { // only update this row if sku is filled in for this row
  23. document.getElementById(nm+i).value = firstitem.value;
  24. }
  25. } else { // not add page, so we just update regardless of if sku is filled in
  26. document.getElementById(nm+i).value = firstitem.value;
  27. }
  28. }
  29. } // looping down the rows
  30. }

Report this snippet  

You need to login to post a comment.