Forum Moderators: open

Message Too Old, No Replies

Form checking done w/Javascript

can people disable that in their browser?

         

5:57 pm on Mar 23, 2005 (gmt 0)



This might sound stupid. I have a form and a form checking script in Javascript to ensure users have filled in their required fields. An alert box will pop up when the user clicks the submit button if a required field is blank. The alert box will continue to pop up no matter how many times they click the submit button until the field is filled in. I was wondering if there's an option in the browser where the user can disable Javascript? If yes, then having a Javascript form checker might not be a good idea.

rocknbil

6:14 pm on Mar 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes they can disable Javascript, and can submit the form (or not) anyway.

If you use <input type="button"> for your submit and Javascript is disabled, it will do . . . nothing. If you use <input type="submit"> it will submit even if required fields are left blank.

I still think it's a good thing, so long as it's not dependent on JS to do it's thing. For example,

<form onSubmit="return false;">
<input type="submit" onClick="checkFields(this.form);" value="go">
</form>
<script language="Javascript">
function checkFields (form) {
//screen . . .
if (err) { alert(msg); }
else { form.submit(); }
}
</script>

If Javascript is off - this form will submit. If not, it will alert any invalid fields and NOT submit. So you've added an "option" that will work in both cases. The return false only stops submission if Javascript is enabled, see?

So sadly, it's required that you screen the same data on the server side. While this is duplication of services, you have to remember that Javascript is an optional feature to enhance the user's experience. If it works, it saves them a back button click if they can't read (we said email is REQUIRED, what where you thinking? :-D )