Validate multiple uploads

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
sulen
Forum Commoner
Posts: 79
Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:

Validate multiple uploads

Post by sulen »

I have a multiple image upload module which has 4 upload textboxes. I need to validate the upload boxes and I am not sure how to do it as the field name is an array name called imagefile[] instead of something static. Any help will be appreciated. Thanks

The general js validation I do for select boxes are as under

Code: Select all

<script language="JavaScript">
function validSelect(formField,fieldLabel)
{
  var result = true;
  if (formField.selectedIndex == 0) 
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
return result;
}
unction validateForm(theForm)
{
// Start ------->
if (!validSelect(theForm.fieldname,"label"))
return false;
// <--------- End
return true;
}
</script>
The multiple image upload code is as under

Code: Select all

<form enctype="multipart/form-data" action="classifieds.php?action=addad3&in=4" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr> 
<td width="30%" align="right"><strong>image to upload:</strong></td>
<td width="80%"> <input name="imagefile[]" id="imagefile[]" type="file" class="txtbox" size="50"></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr> 
<td width="30%" align="right"><strong>image to upload:</strong></td>
<td width="80%"> <input name="imagefile[]" id="imagefile[]" type="file" class="txtbox" size="50"></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr> 
<td width="30%" align="right"><strong>image to upload:</strong></td>
<td width="80%"> <input name="imagefile[]" id="imagefile[]" type="file" class="txtbox" size="50"></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr> 
<td width="30%" align="right"><strong>image to upload:</strong></td>
<td width="80%"> <input name="imagefile[]" id="imagefile[]" type="file" class="txtbox" size="50"></td>
</tr>
</table>
</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<tr bgcolor="#CCCCCC"> 
<td nowrap class="text"><a href="classifieds.php?action=home" class="text">< cancel</a></td>
<td class="text" align="right"> 
<input class='btn' onMouseOver="this.className='btn btnhov'" onMouseOut="this.className='btn'" type="submit" name="submit" value="upload and finish">
</td>
</tr>
</table></td>
</form>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You could give them unique ID values...

I hope this isn't your only form of validation on the uploads.
Post Reply