Which is the following is correct?
a) <form ... onSubmit="retur n checkData()">
b) <form ... onSubmit="retur n checkData();">
c) <form ... onSubmit="check Data()">
d) <form ... onSubmit="check Data();">
....where checkData is a JavaScript function that returns a true or false
value.
It seems that Internet Explorer accepts all of the above, but I'm not
taking that to mean that all are correct.
I've attempted to search the W3 web site on the terms form and onsubmit,
but the documentation refers to the attribute value as being an intrinsic
event (without giving any examples). The archived mailing lists contain
messages which demonstrate all of the options that I've provided above. I
gave up after the forth page of search results because of the number of
conflicting examples.
Does anyone know which is correct?
Thanks for your precious time. 2 6470
On Mon, 15 Nov 2004 15:51:19 GMT, Sean Dockery <sd******@secur ac.net>
wrote: Which is the following is correct?
a) <form ... onSubmit="retur n checkData()">
b) <form ... onSubmit="retur n checkData();">
c) <form ... onSubmit="check Data()">
d) <form ... onSubmit="check Data();">
...where checkData is a JavaScript function that returns a true or false value.
All of them are correct in that they will result in the call of checkData.
However, only a) and b) will actually affect whether the form is submitted.
The content of an intrinsic event attribute becomes the body of an
anonymous function:
/* Note that IE doesn't pass an event argument. It uses a global
* variable of the same name. Either way, you can still use:
*
* on<event>="myFu nction(event)"
*
* to access the event object.
*/
formElement.ons ubmit = function(event) {
/* Value in onsubmit attribute */
};
Obviously, if you don't include a return statement, no value will actually
be returned when this anonymous function exits.
With regards to the semicolon, the same rules apply as normal: semicolons
are generally optional, but it's good practice to include them. If you had
two or more statements/expressions to evaluate, a semicolon would be
necessary to separate them.
The final point I like to make is that it's simpler to pass a reference to
the FORM when it is called, rather than obtain one later. That is:
<form ... onsubmit="retur n checkData(this) ;">
function checkData(form) {
/* You can now use form, rather than
* document.forms['formName']
*/
}
It seems that Internet Explorer accepts all of the above, but I'm not taking that to mean that all are correct.
As I said, they are all syntactically correct, but the second two are
probably not what you want.
[snip]
Hope that helps,
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Thanks, Michael. Your response was extremely helpful, and exactly what I
was looking for.
"Michael Winter" <M.******@bluey onder.co.invali d> wrote in message
news:opshiklmsx x13kvk@atlantis ... On Mon, 15 Nov 2004 15:51:19 GMT, Sean Dockery <sd******@secur ac.net> wrote:
Which is the following is correct?
a) <form ... onSubmit="retur n checkData()">
b) <form ... onSubmit="retur n checkData();">
c) <form ... onSubmit="check Data()">
d) <form ... onSubmit="check Data();">
...where checkData is a JavaScript function that returns a true or false value.
All of them are correct in that they will result in the call of checkData. However, only a) and b) will actually affect whether the form is submitted.
The content of an intrinsic event attribute becomes the body of an anonymous function:
/* Note that IE doesn't pass an event argument. It uses a global * variable of the same name. Either way, you can still use: * * on<event>="myFu nction(event)" * * to access the event object. */ formElement.ons ubmit = function(event) { /* Value in onsubmit attribute */ };
Obviously, if you don't include a return statement, no value will actually be returned when this anonymous function exits.
With regards to the semicolon, the same rules apply as normal: semicolons are generally optional, but it's good practice to include them. If you had two or more statements/expressions to evaluate, a semicolon would be necessary to separate them.
The final point I like to make is that it's simpler to pass a reference to the FORM when it is called, rather than obtain one later. That is:
<form ... onsubmit="retur n checkData(this) ;">
function checkData(form) { /* You can now use form, rather than * document.forms['formName'] */ }
It seems that Internet Explorer accepts all of the above, but I'm not taking that to mean that all are correct.
As I said, they are all syntactically correct, but the second two are probably not what you want.
[snip]
Hope that helps, Mike
-- Michael Winter Replace ".invalid" with ".uk" to reply by e-mail. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Oli |
last post by:
Hi Folks,
Alright, I have a textbox called "A" and the value in that textbox is "B".
When the user presses submit I want A : B to appear on the page. How do I
do it?
I appreciate that this is very basic stuff, but I got to start somewhere!
Cheers (TIA)
|
by: Sue |
last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided
to improve character checking on my project. In my project I only had
to do very basic validation. Therefore, I only had one function to
verify the name fields, age, email and gender.
My question is: if I create a function for each field like the code
below, what would be the best way to organize the functions and call
them? Would I need one main function and place...
|
by: Terry Olson |
last post by:
I'm trying to build a table on an output page based on text input by the
user. And what I am trying to do is create 4 table data boxes on a row, then
start a new row on the 5th one. But I can't quite get it right, the code I
got here will start a new line on odd numbers like 9, 29, 16, etc.What am I
doing wrong?
(ignore any unbalanced braces or the referance to "i", since this is juat a
small snippet.)
if(!isNaN(mxfld) && mxfld != 0) {...
|
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">
This works fine, the form details are collected by RegDetails.asp
I am attempting to include javascript server side validation for the
|
by: bonehead |
last post by:
Greetings,
I'm working on an e-mail form (btw many thanks to Philip Ronan for the
very cool email address format tester function, best I've seen so far).
I've been trying, with limited success, to produce a javascript alert
box which shows the user a validation error message. The error message
itself is dynamic, i.e., it's contained within a php variable.
I seem to be running into two issues:
| |
by: John |
last post by:
Hi,
I have an asp.net form where if the user enters an
incorect date I change the color of the textbox to red and
also display a label field with a message saying the date
is invalid. What I would like to do is to have some way to
trap the event where the user changes the date and reset
the color of the textbox to white and change the error
lablel to hidden. I want to do this before the page gets
submitted back to the server so I've...
|
by: Bruno Alexandre |
last post by:
Hi guys,
Sorry about the off topic, but I can't find the ASP group just the ASP
dot NET
If I want to block a user to change a form after submiting, I add a
function that will disable the submit button, but when I'm getting the form
collection (using post or get (form/querystring) I can't retrieve that
|
by: Bill_W_Stephens |
last post by:
I need a form with two buttons and ability to detect which button was
pressed. I got this code to work using a javascript global variable,
but I know there must be a better way using DOM. Any suggestions?
<html>
<head>
<script language="JavaScript" type="text/javascript">
// global var: which button I am pressing
var btnWhichButton;
|
by: bonneylake |
last post by:
Hey Everyone,
Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section.
Basically i have a multiple select box. An it works except for this one part i want to add to it.The first box i have is called project members which shows the users you can choose to send an email to and the other box is called assignees which is the...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |