Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    173
    Thanks
    2
    Thanked 9 Times in 9 Posts

    file upload type javascript validation

    hi all

    i m using this below script to validate the file to be upload if its extension is .jpg, .gif or .doc.

    this script works fine in Internet explorer but doesnot work in firefox 3.

    can anyone give me an alternative or tell what to add in it.

    vineet

    <script language="javascript">

    function Checkfiles()

    {

    var fup = document.getElementById('filename');

    var fileName = fup.value;

    var ext = fileName.substring(fileName.lastIndexOf('.') + 1);

    if(ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "doc")

    {

    return true;

    }

    else

    {

    alert("Upload Gif or Jpg images only");

    fup.focus();

    return false;

    }

    }

    </script>

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Did you debug it to see why?

    What does var fileName = fup.value; return?

    Use Firebug or an alert to see the value

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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