Forum Moderators: open

Message Too Old, No Replies

Proper way to cripple form entry

javascript,form entry,disable

         

pmmenneg

11:32 pm on Oct 15, 2009 (gmt 0)

10+ Year Member



Have a standard form that I would like to REQUIRE JavaScript validation on. Yes, I double check the data on the server, but I'd like to simply refuse submission of the form unless JavaScript is enabled.

In the past I would typically do something along the lines of using:

<form id="post_form" name="post_form" onsubmit="check(); return false;" action="/script/process.php" method="post">

Where check() validates various fields. Problem with this is that when javascript is disabled, the form can still be submitted, due to using the type="submit" button.

A quick a dirty solution would be switching to a type="button" 'submit' button, but the problems that arise from that are that the onsubmit event of the form tag won't fire, so I'll need to move the validation code to the onclick event of the new button. This should do it, but then the form can only be submitted by a mouse click, and not by enter or tabbing to the button and using a keypress... any suggestions?

Thanks,

P

rainborick

4:48 am on Oct 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You could change the action attribute in the <form> tag to be empty and then if the user's entries validate in check(), change the value of form.action to point to the script that actually does the processing. That way, the form data is only submitted if JavaScript is enabled.

pmmenneg

9:59 pm on Oct 19, 2009 (gmt 0)

10+ Year Member



Solution I used:

Alert user with a noscript tag, and have the submit button disabled in the html, then enabled via javascript on page load.

Thanks,

Paul