![]() |
|
|
+ Search |
![]()
|
Apr 8th, 2008 18:49
ha mo, Dave Clark, bilal ahamd,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bilal,
You can check it either when the field is changed or when the
form is submitted. Just keep in mind that if JavaScript is disabled
then this code won't perform any client-side validation for you. Here
is the function:
var valid_extensions = /(.jpg|.jpeg|.gif)$/i;
//
function CheckExtension(fld)
{
if (valid_extensions.test(fld.value)) return true;
alert('The selected file is of the wrong type.');
fld.select();
fld.focus();
return false;
}
Then, you can call it as follows:
<form onsubmit="return CheckExtension(this.elements['fileupload'])">
<fieldset>
<input type="file" name="fileupload" size="40"
onchange="return CheckExtension(this)">
</fieldset>
</form>
Take care,
Dave Clark
www.DaveClarkConsulting.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com