Results 1 to 2 of 2

Thread: javascript empty file upload field check

  1. #1
    Join Date
    Mar 2010
    Posts
    8

    javascript empty file upload field check

    hi

    is there a way i can check if a file upload field is empty or not with javascript/jquery when the submit button is pressed?

  2. #2
    Join Date
    May 2010
    Location
    Riverside, Ca
    Posts
    241
    This is the general idea, though, I'm pretty sure you can't target a file upload like that. YOu might have to change the type value to a textbox, and then get the value out of there.
    HTML Code:
    <html>
    <body>
    <form id="form" onsubmit="checkForm(event, this;">
    
        Upload File: <input id="fileUpload" type="file" name="file1" value="C:\" />
        <br />
        <input type="submit"  value="Submit" />
        </form>
    
    <script type="text/javascript">
            function checkForm(e, t){
                     if(e.stopPropagation){
                         e.stopPropagation();
                    }
                    else{
                          e.cancelBubble = true;
                    }
    
                    if (e.preventDefault){
                       e.preventDefault();
                    }
                    else{
                          e.returnValue = false;
                    }
                     if(!document.getElementById("fileUpload").value){
                          alert("No file selected");
                     }
                      else{
                            t.submit();
                      }
    
            }
    </script>
    </body>
    </html>
    or you can do:
    Code:
    $('#lform').submit(function(e) {
            stopEvent(e);
    if you use jquery ( I don't so it might not be accurate)
    "The generation of random numbers is too important to be left to chance."

Similar Threads

  1. AS3 - Call Uploaded file into Empty Movieclip
    By oddball25 in forum Graphic Design
    Replies: 0
    Last Post: 31 Dec 2009, 08:37 AM
  2. Creating a file upload form with PHP
    By gilbertsavier in forum Tutorials
    Replies: 0
    Last Post: 04 Aug 2009, 04:44 AM
  3. File extension check
    By Rickzkm in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 24 Feb 2006, 05:45 AM

Posting Permissions

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