943,147 Members | Top Members by Rank

Ad:
Feb 9th, 2010
0

Form still uploads file despite javascript validation error

Expand Post »
Hi all

I have a form where a user can upload a file. I do a check to see if it's a zip file. If it isn't then its supposed to stop the file from being uploaded. Only thing is, the file still uploads regardless of getting the error or not.

How can I prevent the form from submitting the file if the error pops up?

javascript Syntax (Toggle Plain Text)
  1. function checkForm() {
  2. var filename = document.getElementById('file').value;
  3. var fileext = filename.substring(filename.lastIndexOf('.')+1);
  4. if (fileext != 'zip')
  5. {
  6. alert('File must be in zip format (*.zip)');
  7. return false;
  8. }
  9. }
Similar Threads
Reputation Points: 18
Solved Threads: 2
Posting Whiz
Venom Rush is offline Offline
325 posts
since Oct 2007
Feb 9th, 2010
0
Re: Form still uploads file despite javascript validation error
On your HTML form have you included return within the on-submit? I.E.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <form name="" action="" target="_self" onsubmit="return checkForm()">
  2. <!--Form Stuff-->
  3. </form>
=)
Reputation Points: 26
Solved Threads: 31
Posting Whiz
samarudge is offline Offline
354 posts
since May 2008
Feb 9th, 2010
0
Re: Form still uploads file despite javascript validation error
Click to Expand / Collapse  Quote originally posted by samarudge ...
On your HTML form have you included return within the on-submit? I.E.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <form name="" action="" target="_self" onsubmit="return checkForm()">
  2. <!--Form Stuff-->
  3. </form>
=)
It's always the really simple things that seem to escape one's eyes o.O
Reputation Points: 18
Solved Threads: 2
Posting Whiz
Venom Rush is offline Offline
325 posts
since Oct 2007
Feb 10th, 2010
0
Re: Form still uploads file despite javascript validation error
P.S. For those that are unsure of what I was missing. It was the "return " in the onSubmit.
Reputation Points: 18
Solved Threads: 2
Posting Whiz
Venom Rush is offline Offline
325 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Match all array elements or throw alert
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Expanding table with subcells?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC