473,406 Members | 2,745 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,406 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 12110
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>...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.