Author |
Topic  |
|
weeweeslap
Senior Member
   
USA
1077 Posts |
Posted - 04 September 2007 : 22:26:15
|
Hi guys and gals. I grabbed 2 scripts off the internet and merged them to hopefully have file extension validation. While the alert goes off saying that I can only upload jpg files it still continues with the upload rather than just quitting. I was wondering if you guys could take a look at this code and lend a hand with it. I want it so that only .jpg files can be uploaded. The validation works, but after clicking ok on the alert box, the upload continues on and well uploads the file no matter what file extension it is. I'd appreciate your help, here's the link to the file: http://www.weeweeslap.com/scrapbook/up.txt thanks! if the link appears to have been processed, simply view source and the asp code is displayed, not sure why windows 2003 or why windows vista does that to me. Thanks! |
coaster crazy |
|
HuwR
Forum Admin
    
United Kingdom
20595 Posts |
Posted - 05 September 2007 : 04:10:42
|
instead of using a submit button, just use a button, and then do a formObj.submit() in your checkExt function |
 |
|
Shaggy
Support Moderator
    
Ireland
6780 Posts |
Posted - 05 September 2007 : 05:34:31
|
Or, remove the onclick event from your submit input as well as the second onsubmit from your opening form tag and then call checkExt from checkForm like so:function checkForm(){
if(document.form1.fileUpload.value.length>2){
if(checkExt(document.form1)){
return true
}else{
alert("You can only upload jpg images.")
return false
}
}else{
alert("Please select an image file to upload.")
return false
}
} Finally, you can delete the alert and focus from the checkExt function. You can add the focus back in above, if you want; I just left it out.
|
Search is your friend “I was having a mildly paranoid day, mostly due to the fact that the mad priest lady from over the river had taken to nailing weasels to my front door again.” |
Edited by - Shaggy on 05 September 2007 11:22:01 |
 |
|
weeweeslap
Senior Member
   
USA
1077 Posts |
Posted - 05 September 2007 : 10:20:31
|
Cool, thanks guys! All up and running now 
-edit- now even if I do send a proper file it wont process the upload lol Maybe I need to find some better code  |
coaster crazy |
Edited by - weeweeslap on 05 September 2007 10:27:45 |
 |
|
Shaggy
Support Moderator
    
Ireland
6780 Posts |
Posted - 05 September 2007 : 11:22:23
|
Wee error in the code I posted; fixed above.
|
Search is your friend “I was having a mildly paranoid day, mostly due to the fact that the mad priest lady from over the river had taken to nailing weasels to my front door again.” |
 |
|
weeweeslap
Senior Member
   
USA
1077 Posts |
|
Shaggy
Support Moderator
    
Ireland
6780 Posts |
Posted - 05 September 2007 : 12:16:08
|
You replaced your checkExt function with my checkForm function.
|
Search is your friend “I was having a mildly paranoid day, mostly due to the fact that the mad priest lady from over the river had taken to nailing weasels to my front door again.” |
 |
|
weeweeslap
Senior Member
   
USA
1077 Posts |
Posted - 05 September 2007 : 16:11:05
|
oops, ok I fixed what I broke and did it the way yo mentioned above, now when I input an invalid file type it alerts me twice once on clicking submit and once after clicking ok on the first alert box, that I can only use .jpg files but after clicking ok on the second alert box it yet again proceeds with the upload. Here's the updated txt file: http://www.weeweeslap.com/scrapbook/up.txt live test page: http://www.weeweeslap.com/scrapbook/up.asp
Sorry if I am not understanding what you're telling me to change, I still consider myself a newbie to coding even after years of having to deal with it  Forgot to mention that if I do use a valid .jpg file it gives me the alert message once and then proceeds with the upload after clicking ok. |
coaster crazy |
Edited by - weeweeslap on 05 September 2007 17:31:54 |
 |
|
weeweeslap
Senior Member
   
USA
1077 Posts |
Posted - 05 September 2007 : 18:47:53
|
I ditched the whole javascript and did it through an asp way which requires the file to be uploaded but if it is found tonot be of the right file extension, it is deleted immediately. |
coaster crazy |
 |
|
|
Topic  |
|