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

Stopping a Form Checker Script from failing true

P: n/a
Hi,

If I make a mistake designing a JavaScript Form Checker, ie get the name (or case) of a form Field
wrong, JavaScript seems to default to immediately returning true and the form is submitted even
though incomplete. This makes debugging difficult. Can any of the grey matter here advise on how to
get round this, any tips etc.
zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips
Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
zzapper <da***@tvis.co.uk> writes:
If I make a mistake designing a JavaScript Form Checker, ie get the
name (or case) of a form Field wrong, JavaScript seems to default to
immediately returning true and the form is submitted even though
incomplete.
No, it doesn't return true. Instead it fails with an error, which
should be visible somewhere in your browser (javascript console in
Mozilla or Opera, error message in IE if enabled). However, the event
is *only* cancelled if the handler successfully returns "false". Any
other return value, or failing to return at all, will let the event
have its normal effect.
This makes debugging difficult. Can any of the grey
matter here advise on how to get round this, any tips etc.


Enable error messages:
<URL: http://jibbering.com/faq/#FAQ4_43 >

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2

P: n/a
On Thu, 15 Jul 2004 19:08:56 +0200, wrote:
zzapper writes:
If I make a mistake designing a JavaScript Form Checker, ie get the
name (or case) of a form Field wrong, JavaScript seems to default to
immediately returning true and the form is submitted even though
incomplete.


No, it doesn't return true. Instead it fails with an error, which
should be visible somewhere in your browser (javascript console in
Mozilla or Opera, error message in IE if enabled). However, the event
is *only* cancelled if the handler successfully returns "false". Any
other return value, or failing to return at all, will let the event
have its normal effect.
This makes debugging difficult. Can any of the grey
matter here advise on how to get round this, any tips etc.


Enable error messages:
<URL: http://jibbering.com/faq/#FAQ4_43 >


There's something about a Form jumping to a new screen which hides any error display.
zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips
Jul 23 '05 #3

P: n/a
zzapper wrote:
This makes debugging difficult. Can any of the grey
matter here advise on how to get round this, any tips etc.


Enable error messages:
<URL: http://jibbering.com/faq/#FAQ4_43 >


There's something about a Form jumping to a new screen which hides any error display.

zzapper (vim, cygwin, wiki & zsh)


Change:

<script type="text/javascript">
function validate(f) { c = a + b; }
</script>
<form onsubmit="return validate(this);">
<input type="submit" value="Go">
</form>

into:

<script type="text/javascript">
function validate(f) { c = a + b; }
</script>
<form onsubmit="return false && validate(this);">
<input type="submit" value="Go" onclick="validate(this.form);">
</form>

Now even if you make a syntax error in validate() the form won't submit and you'll have
an opportunity to examine the errors.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #4

P: n/a
Grant Wagner <gw*****@agricoreunited.com> wrote in message news:<40***************@agricoreunited.com>...
zzapper wrote:
> This makes debugging difficult. Can any of the grey
> matter here advise on how to get round this, any tips etc.

Enable error messages:
<URL: http://jibbering.com/faq/#FAQ4_43 >
There's something about a Form jumping to a new screen which hides any error display.


<script type="text/javascript">
function validate(f) { c = a + b; }
</script>
<form onsubmit="return false && validate(this);">
<input type="submit" value="Go" onclick="validate(this.form);">
</form>

Now even if you make a syntax error in validate() the form won't submit and you'll have an opportunity to examine the errors.
Nice One!!, (Excellent FAQ as well).

What I 've tried is to have the Form checking script, called by a
simple wrap javascript, but it still doesn't trap the error there
before it hits the form.

(Where the Error is the wrong case of "Fred")
eg

function validate2(f) {
if (f.fred.value.length > 3) return 3;
return 0;
}
function validate(f) {
if (validate2(f) == 3) alert ("ok");
alert ("nok");
}
</script>
<form onsubmit=" validate(this);"

<input type=text name=Fred value="1234">
<input type="submit" value="Go" onclick="validate(this.form);">
</form>

zzapper
Jul 23 '05 #5

P: n/a
(zzapper) wrote in message news:<f6*************************@posting.google.c om>...
Grant Wagner wrote in message news:<40***************@agricoreunited.com>...
zzapper wrote:
>> This makes debugging difficult. Can any of the grey
>> matter here advise on how to get round this, any tips etc.
>
>Enable error messages:
><URL: http://jibbering.com/faq/#FAQ4_43 >

There's something about a Form jumping to a new screen which hides any error display.

Here's a trick that may help during testing

<form method=POST name=form1 action="javascript:alert(form1.test.value)">
<input type=text name=test>
<input type=submit>
</form>

--
zzapper (vim,cygwin,wiki & zsh)

vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips
Jul 23 '05 #6

P: n/a
zzapper wrote:
Here's a trick that may help during testing

<form method=POST name=form1 action="javascript:alert(form1.test.value)"> [1]^^^^^^^^^^ [2]^^^^^^^^^^^ [3]^^^^^^^^^^

[1] Not required unless the "form" element object requires reference
outside of the "form" element or inside in an event handler of a
non-form element (should be avoided).

[2] <http://jibbering.com/faq/#FAQ4_24>

[3] This is proprietary and thus error-prone referencing.
<input type=text name=test> ^^^^^^^^^^ ^ ^ <input type=submit> ^ ^
type="text" is the initial value, and attribute values should be quoted.
</form>


<form action="..." ... method="post"
onsubmit="alert(this.elements['test'].value)">
<input name="test">
<input type="submit">
</form>
PointedEars
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.