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

Posted on 2004-11-30
Last Modified: 2010-04-06
  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

Question by:econcepts
    1 Comment
    LVL 6

    Accepted Solution


    <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; }
        return true; }

    <form method="post" name=f
    onsubmit="return check();"
    Please select a JPEG (.jpg) file to be sent:
    <input type="file" name="pic" size="40"
    Please include a short explanation:<br>
    <textarea name="expl" rows="3" cols="40"
    <input type="submit" value="Send">

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Article by: Matthew
    I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
    Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System ( introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    The viewer will learn how to count occurrences of each item in an array.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now