473,246 Members | 1,349 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,246 software developers and data experts.

Form validation with onclick (vs. onsubmit) in WinXP's IE

I have created web pages that do client-side form validation using the
onclick directive. E.g.,

<form action=other_page.cgi method=post>
Enter your age: <input name=age>
<input type="submit" value="" onclick="return validate_form()">
</form>

where validate_form() returns true or false depending on whether the
user entered a valid age.

This does what I want almost everywhere (e.g., Firefox on FreeBSD,
Safari on Mac, IE on Win2000) but recently I have become aware of an
exception: IE on WinXP.

On WinXP's IE, validate_form() is called (and will display an alert box
if that's that's what I coded), but whether it returns true or false,
the form is submitted. (Then we do the server-side validation and throw
up an error page, but I'd rather catch this client-side.)

So the question I have is: why is WinXP so weird about this? Previous
versions of IE didn't do this.

While looking into this, I've discovered I can also do an onsubmit check
in the form tag, e.g.,

<form action=other_page.cgi method=post onsubmit="return
validate_form()">

Is onsubmit new or has it been around for a while? Can I trust old
Mozillas on Linux to do the right thing with it? Windows is actually a
small portion of the target audience, but I like to make things work for
everyone.

Does it make a difference if the form is submitted to the same page or a
different page? I don't have ready access to Windows XP to test this
out.
Jul 23 '05 #1
3 12096
n3*************@jetable.org wrote:
I have created web pages that do client-side form validation using the
onclick directive. E.g., <form action=other_page.cgi method=post>
Enter your age: <input name=age>
<input type="submit" value="" onclick="return validate_form()">
</form>
That form could be submitted without the user clicking on the submit button.
You're better off using onsubmit.
Is onsubmit new or has it been around for a while?


From the 1999 HTML specification:
http://w3.org/TR/html4/interact/scripts.html#h-18.2.3

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #2
n3*************@jetable.org wrote:
<snip>
<form action=other_page.cgi method=post>
Enter your age: <input name=age>
<input type="submit" value="" onclick="return validate_form()">
</form>

where validate_form() returns true or false depending on
whether the user entered a valid age.

This does what I want almost everywhere (e.g., Firefox on
FreeBSD, Safari on Mac, IE on Win2000) but recently I have
become aware of an exception: IE on WinXP. <snip> While looking into this, I've discovered I can also do
an onsubmit check in the form tag, e.g.,

<form action=other_page.cgi method=post onsubmit="return
validate_form()">

Is onsubmit new or has it been around for a while?
onsubmit has been around for longer than support for onclick handlers on
submit buttons.
Can I trust old
Mozillas on Linux to do the right thing with it?
Depending on what you mean by "the right thing", probably. In general,
when the _user_ submits a form (by any available mechanism for the task,
but not necessarily when a form is submitted by a script) a javascript
capable user agent will call the form's onsubmit handler(s) and allow
them to cancel the submission when necessary. The onsubmit handler is
the _only_ recommendable trigger for form validation.
Windows is actually a small portion of the target
audience, but I like to make things work for everyone.

<snip>

Form validation is probably the one area of browser scripting where all
user agents (at least those that understand what a form is and allow
them to be scripted) can be accommodated with a signal (non
feature-branching) script.

Richard.
Jul 23 '05 #3
David Dorward <do*****@yahoo.com> wrote:
n3*************@jetable.org wrote:
I have created web pages that do client-side form validation using the
onclick directive. E.g.,

<form action=other_page.cgi method=post>
Enter your age: <input name=age>
<input type="submit" value="" onclick="return validate_form()">
</form>


That form could be submitted without the user clicking on the submit button.
You're better off using onsubmit.


This is true. The browsers I had been working with fired off the
onclick handler even if the submit button wasn't actually clicked,
though. That may be technically wrong, but that's what they did.

I'm still curious about the behavior of WinXP's IE. I click on the
button, and the onclick handler fires off, and returns false, but the
form is submitted anyway. Isn't that wrong? Is WinXP's IE following
some specification that all those other browsers aren't aware of, or is
Microsoft just wrong here?
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
6
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: ...
2
by: webbedfeet | last post by:
Hi I hope someone can help me. I have a client side form validation script which works perfectly in IE but clicking "Submit" in Mozilla does nothing - the form won't submit. Is there something I...
2
by: Nick Bell | last post by:
I have a general form validation question. I know very little about javascript, a little more about PHP. Using yav (http://yav.sourceforge.net): <form method="POST" name=edit onsubmit="return...
10
by: iam247 | last post by:
Hi In my prototype asp page (with no javascript and no password validation, I have a registration form with the following action: <form name="form" method="post" action="RegDetails.asp"> ...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
2
by: this one | last post by:
I have the following code <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript"...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
2
by: plumba | last post by:
Ok, another problem... A bit querky this one.. My form calls an onsubmit function to check fields for completion (validation check). Here is a breakdown version of the form: <html>...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.