By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,765 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,765 IT Pros & Developers. It's quick & easy.

best-practice form checking

P: n/a
I've constructed this form so that if Javascript is disaabled it will
show a typical <input type="submit"> button, BUT using the <noscript>
tag. Why is this a problem and what's a viable solution? i'm not sure
of the best way to do this so help is very much appreciated; snide,
smartass, unhelpful comments are useless. Please keep them to
yourself.
Jul 20 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
cruiserweight wrote:
I've constructed this form so that if Javascript is disaabled it
will show a typical <input type="submit"> button, BUT using the
<noscript> tag. Why is this a problem and what's a viable solution?
The question is why you've done this. Why is a submit button only
available in no-js situations?
snide, smartass, unhelpful comments are useless. Please keep them
to yourself.

Best not to cop an attitude, especially before you've gotten any help.

--
Brian (remove ".invalid" to email me)

Jul 20 '05 #2

P: n/a
ba*****@yahoo.com (cruiserweight) wrote:
I've constructed this form so that if Javascript is disaabled it will
show a typical <input type="submit"> button, BUT using the <noscript>
tag.
What happens for users who do have JavaScript enabled? Do they get a
submit button at all?

In what way does it benefit some users _not_ to have an instantly
recognisable submit button?
Why is this a problem and what's a viable solution?
<noscript> is a blunt instrument. What if the user's browser supports
JavaScript but doesn't support all the individual parts that need to
be used to do whatever it is that you're doing?
i'm not sure
of the best way to do this so help is very much appreciated;


Write the form in HTML with a server side script that handles the
submission fully (including any checking that needs to be done).

Then add JavaScript on top of that to perform client side checking
(the time saved will benefit those who have JS enabled). This

JavaScript should be triggered via the onsubmit event handler of the
form (or equivalent event listener methods), not via the onclick event
handler of a particular button, etc.

This JavaScript should also be written so that the browser falls back
to submitting the form to the server in cases where the JavaScript can
not be processed - it should only ever not submit the form if a
definite error is detected in the data.

Technical questions on JS would be better directed to
comp.lang.javascript

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #3

P: n/a
ba*****@yahoo.com (cruiserweight) wrote:
I've constructed this form so that if Javascript is disaabled it will
show a typical <input type="submit"> button, BUT using the <noscript>
tag. Why is this a problem and what's a viable solution? i'm not sure
of the best way to do this so help is very much appreciated; snide,
smartass, unhelpful comments are useless.
Is it being a smartass, and therefore useless, to bring to your
attention the fact that only a psychic can help you if you keep the
trouble-causing code a secret?
Please keep them to
yourself.


I'm so profoundly sorry for having wasted your time, but I couldn't
resist. May we now have *your* apologies for having wasted *our* time
by asking for help without providing relevant information?

--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 20 '05 #4

P: n/a
Harlan Messinger <hm*******************@comcast.net> wrote in message news:<7e********************************@4ax.com>. ..
ba*****@yahoo.com (cruiserweight) wrote:
I've constructed this form so that if Javascript is disaabled it will
show a typical <input type="submit"> button, BUT using the <noscript>
tag. Why is this a problem and what's a viable solution? i'm not sure
of the best way to do this so help is very much appreciated; snide,
smartass, unhelpful comments are useless.


Is it being a smartass, and therefore useless, to bring to your
attention the fact that only a psychic can help you if you keep the
trouble-causing code a secret?
Please keep them to
yourself.


I'm so profoundly sorry for having wasted your time, but I couldn't
resist. May we now have *your* apologies for having wasted *our* time
by asking for help without providing relevant information?

Point well-taken. Apologies all around. The form is at
http://www.veiyotonle.com/printablem...enu=printables. I put a
regular submit button inside noscript tags, and then used javascript
to writeln the code for the javascript button. fields are checked in
javascript (if enabled) and on the server. I've read in these groups
recently, i forget where, that this is not a very good way to do
things. I was to find a better way. Again, sorry for the a-hole
comments.
Jul 20 '05 #5

P: n/a
"cruiserweight" <ba*****@yahoo.com> a écrit dans le message de
news:18**************************@posting.google.c om
I put a
regular submit button inside noscript tags, and then used javascript
to writeln the code for the javascript button. fields are checked in
javascript (if enabled) and on the server.


Err, why don't use the onSubmit event ? It works perfectly for non enabled
javascript ua as for enabled ones !

Please see :
http://devedge.netscape.com/library/...s.html#1121163

Jul 20 '05 #6

P: n/a
"Pierre Goiffon" <pg******@nowhere.invalid> wrote:
"cruiserweight" <ba*****@yahoo.com> a écrit dans le message de
news:18**************************@posting.google. com
I put a
regular submit button inside noscript tags, and then used javascript
to writeln the code for the javascript button. fields are checked in
javascript (if enabled) and on the server.
Err, why don't use the onSubmit event ?


The onsubmit attribute has nothing to do with whether a button is
drawn via Javascript or directly with HTML.
It works perfectly for non enabled
javascript ua as for enabled ones !
Assuming we *are* talking about onsubmit, Javascript certainly is
required for onsubmit to have any effect.

Please see :
http://devedge.netscape.com/library/...s.html#1121163


....where it says, "Executes JavaScript code when a submit event
occurs; that is, when a user submits a form." In other words,
Javascript has to be enabled for it to do anything.

--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 20 '05 #7

P: n/a
cruiserweight wrote:
I've constructed this form so that if Javascript is disaabled
it will show a typical <input type="submit"> button, BUT using
the <noscript> tag.
regular submit button inside noscript tags, and then used
javascript to writeln the code for the javascript button. fields
are checked in javascript (if enabled) and on the server.


Too complicated, and too prone to failure. Create a form using only
html, forget completely about js. Create whatever validation you need
on the server. When the form works perfectly without js, add a js
validation routine, and attach it to the form's onsubmit handler. Have
the routine return false if there's an error.

http://www.xs4all.nl/~sbpoley/webmatters/formval.html

--
Brian (remove ".invalid" to email me)

Jul 20 '05 #8

P: n/a
"Harlan Messinger" <hm*******************@comcast.net> a écrit dans le
message de news:ho********************************@4ax.com
Err, why don't use the onSubmit event ?


The onsubmit attribute has nothing to do with whether a button is
drawn via Javascript or directly with HTML.


Well I wrote my post a little to fast. As I understand it, but it's not
perfectly clear, it seems Cruiserweight is using writeln to had JavaScript
checks for his form. If this is it, it could be replaced by a function
called in the onSubmit event. In fact I was answering that because
unfortunately JavaScript validation that blocks non-enabled Javascript ua is
very common. Just what I guessed reading Cruiserweight.

By the way Cruiserweight, maybe you should explain exactly what is the
difference between the normal html submit button and what is written via JS
? Is it just Javascript validation, or is there another things ?

Jul 20 '05 #9

P: n/a
Oops forgot to say...

"Harlan Messinger" <hm*******************@comcast.net> a écrit dans le
message de news:ho********************************@4ax.com
Err, why don't use the onSubmit event ?


Javascript has to be enabled for it to do anything.


Yes exactly, but Cruiserweight said there are a client side checking via
JavaScript, plus a server side one :
fields are checked in
javascript (if enabled) and on the server.


Jul 20 '05 #10

P: n/a
ba*****@yahoo.com (cruiserweight) wrote:

Point well-taken. Apologies all around. The form is at
http://www.veiyotonle.com/printablem...enu=printables. I put a
regular submit button inside noscript tags, and then used javascript
to writeln the code for the javascript button. fields are checked in
javascript (if enabled) and on the server. I've read in these groups
recently, i forget where, that this is not a very good way to do
things.
I gave one possible reason in my earlier post. Another is that your
way uses more code than the alternative.
I was to find a better way.


Change:
if ( good2go > 0) {
document.printform.submit();
return false;
}

to:
if ( good2go > 0) { return true; }

Change:
<form name="printform" method="post" action="print.html?menu=other">
to:
<form name="printform" method="post" action="print.html?menu=other"
onclick="return validate();">

Change:
<noscript><p class="body"><input type="submit" value="Print Selected"
name="Print Selected" /></p></noscript>
<script type="text/javascript"><!--
document.writeln ("<div><a href=\"#\" onClick=\"return validate();\"
class=\"button\">Print Selected</a></div>");
// --></script>

to:
<p class="body"><input type="submit" value="Print Selected"
name="Print Selected" /></p>

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #11

P: n/a
Brian <us*****@julietremblay.com.invalid> wrote in message news:<40******@news-1.oit.umass.edu>...
cruiserweight wrote:
I've constructed this form so that if Javascript is disaabled it
will show a typical <input type="submit"> button, BUT using the
<noscript> tag. Why is this a problem and what's a viable solution?


The question is why you've done this. Why is a submit button only
available in no-js situations?
snide, smartass, unhelpful comments are useless. Please keep them
to yourself.

Best not to cop an attitude, especially before you've gotten any help.


absolutely right.
Jul 20 '05 #12

P: n/a
Steve Pugh <st***@pugh.net> wrote in message news:<u2********************************@4ax.com>. ..
ba*****@yahoo.com (cruiserweight) wrote:
I've constructed this form so that if Javascript is disaabled it will
show a typical <input type="submit"> button, BUT using the <noscript>
tag.


What happens for users who do have JavaScript enabled? Do they get a
submit button at all?

In what way does it benefit some users _not_ to have an instantly
recognisable submit button?


I believe this is the correct question. It benefits no one for 'some
users _not_ to have an instantly recognisable submit button'.

However, I'd really like to get away from, or at least explore,
options to the standard UI available through html. Overindulgent?
Perhaps a little. In this case, though, I will rework it to use the
onsubmit event handler as suggested and go with the admittedly
unnecessary javascript button.
Jul 20 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.