Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input Type=File & File Types

Status
Not open for further replies.

CherylD

Programmer
May 1, 2001
107
CA
How do(can) you specify what file types to include when when using input type=file? Like only jpg's or gifs.

Thanks.

Cheryl
 
hi
looks like there is no way of doin this via javascript...
but u're able 2 check what was selected & ask 2 select smth that u want...


<html>
<head>
<title>forms</title>
<script>
function checkit(){
var str=document.forms.form1.fill.value
var len=str.length
var pos=str.lastIndexOf('.')+1
var rest=len-pos
var ext=str.substr(pos,rest)
if (ext!='gif' && ext!='jpg')
alert('u shuld select some picture')
}
</script>
</head>

<body bgcolor=&quot;#FFFFFF&quot;>
<form name=form1 >
<input type=button value=&quot;c file accepts&quot; onclick=&quot;checkit()&quot;>
<input type=file name=fill >
</form>
</body>
</html>

and then set checkit() onsubmit or whatever u want...

hope that helped...

regards, vic
 
Hi,

by using the input type=file tag, is impossible to do this.

(the accept=&quot;..&quot; parameter not work).

you may use the common dialog in javascript:

function browse_file() {
var cdl = new ActiveXObject&quot;MsComDlg.CommonDialog&quot;);
cdl.maxFileSize=256;
cdl.filter=&quot;Imagens|*.gif;*.jpg;*.bmp&quot;;
cdl.showopen();
alert('Selected file: '+cdl.filename);
}

this work fine.
Sergio Martins Netto.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top