View Single Post
Old 09-05-2012, 12:01 PM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,102
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
The accept attribute is not supported in Internet Explorer and Safari. That makes it pretty useless.

Code:
<input type = "file" id = "myfile" size = "50" onchange = "checkit()">

<script type = "text/javascript">
function checkit() {
var f = document.getElementById("myfile").value;
if (!/(gif)|(jpg)|(png)$/gi.test(f)) {
alert ("Invalid file type.  Please try again");
return false;
}
}

</script>

A man generally has two reasons for doing things - the one that sounds good, and the real one. - J.P.Morgan
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
MrTIMarshall (09-06-2012)