Looping current div contents - Javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Looping current div contents - Javascript

Post by iknownothing »

Hey Guys,

I have an upload script where the client should beable to specify how many files he has to upload, then javascript will multiply the existing 1 file upload which is already there.

I've got this so far, but its not working, is there a way to actually put the contents into a variable, because I believe innerHTML doesn't do this

filestobeuploaded is the div, which i need to multiply all content/html inside it. all form element names are already arrays, so element naming wont be an issue.

Code: Select all

function doMassMultiply(){
     var addcount = document.getElementById('addcount');
     var dafiles = document.getElementById('filestobeuploaded');
     var dahtml = document.getElementById('filestobeuploaded').innerHTML;										
     for (i=1;i<=addcount;i++){
          dafiles.write(dahtml);
      }
 }
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post by Jonah Bron »

How about this?

Code: Select all

<script type="text/javascript">
function doMassMultiply(element){
  var addcount = element.value;
  var filestoupload = document.getElementById('filestoupload').innerHTML;
  filestoupload = "";
  for (i=0;i<addcount;i++){
    filestoupload += "<input type=\"text\" name=\"uploadbox"+i+"\" /><br />";
  }
}
</script>
<input type="text" name="addcount" onkeyup="doMassMultiply(this);" />
<div id="filestoupload"></div>
Post Reply