Reliable "JavaScript-Required" for Forms
On-the-fly error checking, automatic submission detection,
updating totals -- these are just some of the things
JavaScript can do within forms. Sometimes, things work a
little oddly, if they work at all, when a
JavaScript-disabled browser uses the form.
There may be times when a certain form may not be used at
all except by browsers with JavaScript enabled.
There is a reliable way to require browsers to have
JavaScript enabled when the form is loaded. Else, they can't
submit the form.
The answer is to use JavaScript to publish the submit
button. With no JavaScript, there will be no submit button.
Here is the code:
document.write('<input type="submit">');
Granted, that is a simplistic submit button. It is meant as
an example.
For production forms, either use
the "Convert Text to JavaScript" generator at BontragerCGI.com
or manually convert your current submit button code.
To do it manually, copy the submit button code and:
-
Escape all backward slash characters with another
backward slash. It would look like this: \\
-
Escape all single quote characters with a backward
slash. It would look like this: \'
-
Append "');" (without the quotes) to the end of the
submit button code.
-
Prepend "document.write('" (without the quotes) to
the front of the submit button code.
-
Put the result between SCRIPT tags.
Replace your current submit button code with the one
converted to JavaScript.
Thereafter, when a JavaScript-disabled browser loads your
form, there is no submit button.
It may be prudent to put the following in a prominent position to let users of non-JavaScript browsers know they won't be able to use the form:
<noscript>
<h3>Javascript must be enabled to use this form!<h3>
</noscript>
Question:
Did you find this article interesting and understandable? How can it be improved?
Your response is anonymous.
When done typing, click anywhere outside the box. [more info]
Will Bontrager
©Copyright 2007 Bontrager Connection, LLC Bontrager Connection, LLC
Please note:
Articles on this website are presented "as is". However -
If you have a question about a CGI script, HTML, CSS, PHP, or JavaScript
Ask one of our Experts and you'll have your answer!
Click here for details.