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. Link to comment https://forums.phpfreaks.com/topic/164503-counting-number-of-times-a-function-has-run/ 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? Link to comment https://forums.phpfreaks.com/topic/164503-counting-number-of-times-a-function-has-run/#findComment-867714 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.