• Top Members
    Reps
    Posts
  • 834 Replies
    2585 Replies
  • 716 Replies
    2026 Replies
  • 331 Replies
    1928 Replies

Help with HTML Form and JS Function

User avatar
Livengood
Serious Programmer
Posts: 440

Help with HTML Form and JS Function

Wed Aug 08, 2012 12:52 pm

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?
Image

User avatar
Livengood
Serious Programmer
Posts: 440

Re: Help with HTML Form and JS Function

Wed Aug 08, 2012 6:34 pm

Nvm, i have solved this.
Image

Post Reply

Return to “Tutorials”