Validating Image field for Uploading Images in javascript.


/ Published in: PHP
Save to your folder(s)

javascript image uplaod


Copy this code and paste it in your HTML
  1. <script language="javascript">
  2. function Checkfiles()
  3. {
  4. var fup = document.getElementById('filename');
  5. var fileName = fup.value;
  6. var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
  7. if(ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "doc")
  8. {
  9. return true;
  10. }
  11. else
  12. {
  13. alert("Upload Gif or Jpg images only");
  14. fup.focus();
  15. return false;
  16. }
  17. }
  18. </script>
  19.  
  20.  
  21. <li class="two">
  22. <div class="left_nor"><input type="file" id="logo1" onchange="Checkfiles()" multiple accept='image/*' name="txtLogoFileName" tabindex="20" value="<?php if($_POST["txtLogoFileName"]) echo $_POST["txtLogoFileName"]; else echo($LogofileName); ?>" /></div> </li>

URL: http://stackoverflow.com/questions/8021880/javascript-validate-filename-before-upload

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.