473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Stopping a Form Checker Script from failing true

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
6 1352
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
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
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
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
(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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lawtonl | last post by:
Hi, i've got a asp page to register a user and check that the username has not been previously registered, heres the code i have ... that doesnt work <SCRIPT LANGUAGE=vbscript RUNAT=server> ...
2
by: Axel Foley | last post by:
I used some of the excellent resources from DITHERING.COM for help in my groveling newbie attempts to cough up working form validation.... I cut and pasted bits of code to check USA ZIP codes and...
10
by: Steve Benson | last post by:
Our regular programmer moved on. I'm almost clueless in Javascript/ASP and got the job of adapting existing code. In the page below, everything works until I added the function checkIt() to...
6
by: Dave | last post by:
I have a situation where I want to react to a ctrl-click on a <span> and it works in Netscape and Firefox browsers but in IE I have a problem. In IE I do catch the ctrl-click but IE also renders...
0
by: 2G | last post by:
Hi I'm trying to safely stop a thread but as you might have guessed, I'm failing at it. GetCurrentThread seems to get the wrong handle, my form disappears when I try to stop the thread and it...
5
by: Moon Chow | last post by:
Hello, can anyone help me write a fragment of code to check to see if textarea form input contains the string "http" ? I've successfully created form checking functions with IF statements like...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
11
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or...
1
by: raghudr | last post by:
Hi all, I am displaying a splash screen for which i have created a thread.Since my whole project is launched by windows service and that service will start automatically at the start of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.