magicmoose Posted July 2, 2009 Share Posted July 2, 2009 Hi, I'm using PHP to upload an unset number of images in a form. I'm trying to use javascript to add more form elements in order to allow the correct number of images to be uploaded. <script language="javascript" type="text/javascript"> function addContent(divName) { content = '<label for=\"file1\">File to upload:</label><input id=\"file1\" type=\"file\" name=\"userfile[]\" /><br />'; document.getElementById(divName).innerHTML += content; } </script> <li onclick="addContent('additemform');">More</li> The problem is, I need to replace the numbers (eg file1), with the number of times the function has been run, otherwise each file will have the same id. Is there a simple way to do this? Thanks. Quote Link to comment Share on other sites More sharing options...
gevans Posted July 2, 2009 Share Posted July 2, 2009 <script language="javascript" type="text/javascript"> var count = 0; function addContent(divName) { var content = '<label for="file' + count + '">File to upload:</label><input id="file' + count + '" type="file" name="userfile[]" /><br />'; document.getElementById(divName).innerHTML += content; count = count+1; } </script> Something like that? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.