0

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?

function checkForm() {
	var filename = document.getElementById('file').value;
	var fileext = filename.substring(filename.lastIndexOf('.')+1);
	if (fileext != 'zip')
	{
		alert('File must be in zip format (*.zip)');
		return false;
	}
}
2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Venom Rush
0

On your HTML form have you included return within the on-submit? I.E.

<form name="" action="" target="_self" onsubmit="return checkForm()">
<!--Form Stuff-->
</form>

=)

0

On your HTML form have you included return within the on-submit? I.E.

<form name="" action="" target="_self" onsubmit="return checkForm()">
<!--Form Stuff-->
</form>

=)

It's always the really simple things that seem to escape one's eyes o.O :P

0

P.S. For those that are unsure of what I was missing. It was the "return " in the onSubmit.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.