• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

How to restrict a textbox in HTML to open file dialog with certain extensions

Hi
  I am using JSP, HTML and java script to make my page. I have to make one page which will have textbox and one button. If i click that button i have to open that file open dialog. In that dialog i have to restrict with some extension. After selecting the file with my given extension i have to paste the path in text box

Can u tell me how can i  do that

Rgds
0
econcepts
Asked:
econcepts
1 Solution
 
abdullah716Commented:
http://www.cs.tut.fi/~jkorpela/forms/file.html#filter

<script type="text/javascript" language="JavaScript"><!--
function check() {
  var ext = document.f.pic.value;
  ext = ext.substring(ext.length-3,ext.length);
  ext = ext.toLowerCase();
  if(ext != 'jpg') {
    alert('You selected a .'+ext+
          ' file; please select a .jpg file instead!');
    return false; }
  else
    return true; }
//--></script>

<form method="post" name=f
enctype="multipart/form-data"
onsubmit="return check();"
action="http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi">
<p>
Please select a JPEG (.jpg) file to be sent:
<br>
<input type="file" name="pic" size="40"
accept="image/jpeg">
<p>
Please include a short explanation:<br>
<textarea name="expl" rows="3" cols="40"
onfocus="check();">
</textarea>
<p>
<input type="submit" value="Send">
</form>
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now