duplicate file verification

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chunk1978
    New Member
    • Jan 2007
    • 224

    duplicate file verification

    hello. i'd like to know if there's a way in JavaScript to distinguish a difference between two file fields for verification.

    on the form i am writing, there are 2 file fields far apart from each other, so a user does not see them on the same page level... therefore i think it would be a good idea to write a validation check to see if the user accidently entered the same file in both fields... however, i'm having a difficult time trying to imagine how i would do that...

    perhaps something like the following?

    Code:
    function ValidateDuplicateFile()
         {
         var File1 = document.form.file1.value;
         var File2 = document.form.file2.value;
    
         if (File1 = File2){
         alert( "Both of your files are the same" );
         document.form.file1.value.focus();
         return false;}
    
         return true;
    }
    sorry i have no way to test this right now, so if any of you JavaScript geniuses think this code would work for me, please let me know. thanks a lot!
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    I've modified your code below:
    Code:
    function ValidateDuplicateFile()
         {
         var File1 = document.form.file1.value;
         var File2 = document.form.file2.value;
    
         if (File1 == File2){
         alert( "Both of your files are the same" );
         document.form.file1.focus();
         return false;}
    
         return true;
    }
    Notice the changes I made:
    1. File1=File2 replaced by File1==File2 (comparing instead of assigning/setting).
    2. focus() is a method of the file input object, not value (which is an attribute of the file input object and therefore cannot have methods).

    Comment

    • chunk1978
      New Member
      • Jan 2007
      • 224

      #3
      Originally posted by acoder
      I've modified your code below
      excellent... thanks again acoder!

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        No problem. You're welcome.

        Comment

        Working...