Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Reply to Thread

Post a reply to the thread: <input type=file> html javascript question?

Your Message

Click here to log in

What comes after M0nday

 
 

You may choose an icon for your message from this list

Additional Options

  • Will turn www.example.com into [URL]http://www.example.com[/URL].

Rate Thread

You may rate this thread from 1-star (Terrible) to 5-stars (Excellent) if you wish to do so.

Topic Review (Newest First)

  • 12-29-2010, 04:28 AM
    ApurvA

    <input type=file> html javascript question?

    JAI MATADI all ..

    i m doing validation in <input type=file> in which the user will only be able to select pictures .. if he/she has selected a document or another file .. he/she will get error ..

    here is my code in which i m facing a bit problem ..

    --------------------------------------------------
    mytry.php
    -------------------------------
    <script type="text/javascript">
    function ab(field,ext)
    {
    if (field.value.indexOf('.' + ext) == -1)
    {
    alert('Your uploaded file must be a .' + ext + ' type file.\nPlease select again.');
    field.focus();
    return false;
    }
    return true;
    }

    </script>
    </head>

    <body>
    <form name="form1" id="form1" method="post" enctype="multipart/form-data" onsubmit="return ab(f1,'jpg')">
    <input type="file" name="f1" id="f1" />
    <input type="submit" name="submit" id="submit" />
    </form>
    ------------------------------------------------------------------------------------

    m able to validate this code .. i want to add multiple validations (for gif,png) etc with this also ..

    how can i do this .. if you have any query or link or yor own code .. please let me know .. as m able to get validation result here but for only single "jpg"

    help me if you can ..

    thank you ..
    here m getting only the validation for (.jpg) but i want to add (gif,png) etc validations also in this ..

    how can i do thiss ..
    i have also tried this

    <input type="file" accept="image/jpg, image/gif">

    but nothing seems to be working

    please help ..
    @boeard678's

    i have tried your code like this .. as m want to use || not &&
    ---------------------------------------------------------
    <script type=text/javascript>
    function ab(field)
    {
    if ((field.value.indexOf('.' + ext) == -1) || (field.value.indexOf('.jpeg') == -1 ))
    {
    alert('Your uploaded file must be a jpeg type file.\nPlease select again.');
    field.focus();
    return false;
    }
    return true;
    }

    </script>
    ---------------------------------------------------------

    but its not working for me ..

    help me

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •