{ Learn Code. Share Code. Teach Code. Love Code. }

  • Help with HTML Form and JS Function

 #70677  by Livengood
 Wed Aug 08, 2012 11:52 am
Alright, so i have this
Code: Select all
<script language="javascript" type="text/javascript">
	function addField() {
		var count = document.getElementById('count').value;
		count++;
		var hello = document.getElementById('photo_tbl').innerHTML;
		document.getElementById('photo_tbl').innerHTML = hello + "<tr><td width='35%'><label>Image "+count+": </label></td><td width='75%'><input type='file' name='uplimg"+count+"'></td></tr><tr><td><label>Caption: </label></td><td><input style='width: 97%;' type='text' name='caption"+count+"'></td></tr>";
		document.getElementById('count').value = count;
	}
</script>
<div style="width: 100%;padding-top:75px;padding-bottom:75px;" align="center">
	<font size="6">Upload Photos</font>
	<form name="new_image" method="post" enctype="multipart/form-data" action="index.php?action=uploading_photos">
		<table id="photo_tbl" class="upload_table">
			<tr>
				<td width="35%">
					<label>Image 1: </label>
				</td>
				<td width="75%">
					<input type="file" name="uplimg1'">
				</td>
			</tr>
			<tr>
				<td>
					<label>Caption: </label>
				</td>
				<td>
					<input style="width: 97%;" type="text" name="caption1'">
				</td>
			</tr>
		</table>
		
		<br />
		
		<table class="upload_table">
			<tr>
				<td>
					<input name="count" type="hidden" id="count" value="1"/>
					<input name="add" type="button" class="button" id="add" value="Add Another Photo" onClick="addField();"/>
				</td>
				<td align="right">
					<input class="button" name="Submit" type="submit" value="Upload">
				</td>
			</tr>
		</table>
	 </form>
 </div>
But lets say you enter in data and then click add another photo then it resets the whole thing. How can i fix this?