On page 392 of "Javascript the definitive guide" a function is called
like this:-
<form action="process form.cgi" onsubmit="retur n validateForm(); ">
Why, in this instance, is the return statement used in calling the
function validateForm rather than being included inside the function?
Thanks in advance, 13 7785
Steve <st***********@ googlemail.comw rites:
On page 392 of "Javascript the definitive guide" a function is called
like this:-
<form action="process form.cgi" onsubmit="retur n validateForm(); ">
Why, in this instance, is the return statement used in calling the
function validateForm rather than being included inside the function?
Because onsubmit="retur n validateForm(); " is roughly equivalent to
element.onsubmi t = function() { return validateForm(); };
While, onsubmit="valid ateForm();" would be equivalent to
element.onsubmi t = function() { validateForm(); };
Also note that there is direct equivalent to element.submit = validateForm;
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Joost Diepenmaat <jo***@zeekat.n lwrites:
Also note that there is direct equivalent to element.submit = validateForm;
^^^^^^^^^ I meant "...is NO direct..."
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Joost Diepenmaat wrote:
Joost Diepenmaat <jo***@zeekat.n lwrites:
>Also note that there is direct equivalent to element.submit = validateForm;
^^^^^^^^^ I meant "...is NO direct..."
There is, but it makes no sense in the first place. If it worked, you would
be overwriting the form object's submit() method.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8************ *******@news.de mon.co.uk>
On Jun 7, 8:11 pm, Joost Diepenmaat <jo...@zeekat.n lwrote:
Steve <stephen.jo...@ googlemail.comw rites:
On page 392 of "Javascript the definitive guide" a function is called
like this:-
<form action="process form.cgi" onsubmit="retur n validateForm(); ">
Why, in this instance, is the return statement used in calling the
function validateForm rather than being included inside the function?
Because onsubmit="retur n validateForm(); " is roughly equivalent to
element.onsubmi t = function() { return validateForm(); };
While, onsubmit="valid ateForm();" would be equivalent to
element.onsubmi t = function() { validateForm(); };
Thanks for the answer but I still don't get it. What would be the
difference in effect between calling
"element.onsubm it = function() { return validateForm(); };" and
calling
"element.onsubm it = function() { validateForm(); };" ?
Cheers.
Steve <st***********@ googlemail.comw rites:
Thanks for the answer but I still don't get it. What would be the
difference in effect between calling
"element.onsubm it = function() { return validateForm(); };" and
calling
"element.onsubm it = function() { validateForm(); };" ?
the second variant doesn't propagate the return value of
validateForm() to the form. you usually want to, because returning
false from an onsubmit handler will cancel the submit (while returning
nothing at all or true would cause the submit to continue). Not much
point in checking form fields and then just submitting it if it
doesn't validate.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
On Jun 7, 9:22 pm, Joost Diepenmaat <jo...@zeekat.n lwrote:
Steve <stephen.jo...@ googlemail.comw rites:
Thanks for the answer but I still don't get it. What would be the
difference in effect between calling
"element.onsubm it = function() { return validateForm(); };" and
calling
"element.onsubm it = function() { validateForm(); };" ?
the second variant doesn't propagate the return value of
validateForm() to the form. you usually want to, because returning
false from an onsubmit handler will cancel the submit (while returning
nothing at all or true would cause the submit to continue). Not much
point in checking form fields and then just submitting it if it
doesn't validate.
--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
Yes but why not include the return statement inside the function, like
this:
function validateForm() {
if (document.forms[1].element[2]==null) {
return false;
}
else {
return true;
}
}
Cheers
"Steve" <st***********@ googlemail.coms chreef in bericht
news:af******** *************** ***********@s50 g2000hsb.google groups.com...
On Jun 7, 9:22 pm, Joost Diepenmaat <jo...@zeekat.n lwrote:
>Steve <stephen.jo...@ googlemail.comw rites:
Thanks for the answer but I still don't get it. What would be the
difference in effect between calling
"element.onsubm it = function() { return validateForm(); };" and
calling
"element.onsubm it = function() { validateForm(); };" ?
the second variant doesn't propagate the return value of validateForm () to the form. you usually want to, because returning false from an onsubmit handler will cancel the submit (while returning nothing at all or true would cause the submit to continue). Not much point in checking form fields and then just submitting it if it doesn't validate.
-- Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
Yes but why not include the return statement inside the function, like
this:
function validateForm() {
if (document.forms[1].element[2]==null) {
return false;
}
else {
return true;
}
}
Gentlemen experts, would it be correct to explain it in this way? :
Consider what you would have to code in the case there is no function but a
predefined value. For instance, you want to disable the submission of form
input.
You could have:
var submissionBlock = false;
element.onsubmi t = return submissionBlock ;
Meaning: pass the value of submissionBlock to the form. If you had
element.onsubmi t = submissionBlock
it would assign the value of submissionBlock to the property onsubmit of
element (which would not affect the form's excution).
Tom
On Jun 7, 11:47 pm, Steve <stephen.jo...@ googlemail.comw rote:
On Jun 7, 9:22 pm, Joost Diepenmaat <jo...@zeekat.n lwrote:
Steve <stephen.jo...@ googlemail.comw rites:
Thanks for the answer but I still don't get it. What would be the
difference in effect between calling
"element.onsubm it = function() { return validateForm(); };" and
calling
"element.onsubm it = function() { validateForm(); };" ?
the second variant doesn't propagate the return value of
validateForm() to the form. you usually want to, because returning
false from an onsubmit handler will cancel the submit (while returning
nothing at all or true would cause the submit to continue). Not much
point in checking form fields and then just submitting it if it
doesn't validate.
--
Joost Diepenmaat | blog:http://joost.zeekat.nl/|work:http://zeekat.nl/
Yes but why not include the return statement inside the function, like
this:
function validateForm() {
if (document.forms[1].element[2]==null) {
return false;
}
else {
return true;
}
}
You could check it yourself: in this case the form will be submitted
in either case _if_ validateForm is called from the intrinsic event
handler.
<form ... onsubmit="valid ateForm(this)">
is in fact internally
<form ... onsubmit= function anonymous() { validateForm(th is); }>
It means that no matter what validateForm returns, function anonymous
returns nothing (undefined) which is treated as a permission to submit
the form. It is an initial DOM 0 algorithm "oops" which is now
sustained by an ocean of existing scripts, so it is very hard (~=
impossible) to change it. Someone was thinking Perl I guess while
defining the procedure so he/she forgot that Javascript doesn't have
implicit return values for subroutines. The right algorithm would be
"if intrinsic onsubmit handler is set but returns nothing then treat
it as if it returns false". Too late to cry over it anyway. So the
regular algorithm fix is by using "piped return" like
<form ... onsubmit="retur n validateForm(th is)">
Tom de Neef wrote:
"Steve" <st***********@ googlemail.coms chreef [...]:
>On Jun 7, 9:22 pm, Joost Diepenmaat <jo...@zeekat.n lwrote:
>>Steve <stephen.jo...@ googlemail.comw rites: Thanks for the answer but I still don't get it. What would be the difference in effect between calling "element.ons ubmit = function() { return validateForm(); };" and calling "element.ons ubmit = function() { validateForm(); };" ? the second variant doesn't propagate the return value of validateForm( ) to the form. you usually want to, because returning false from an onsubmit handler will cancel the submit (while returning nothing at all or true would cause the submit to continue). Not much point in checking form fields and then just submitting it if it doesn't validate.
Yes but why not include the return statement inside the function, like this:
function validateForm() { if (document.forms[1].element[2]==null) { return false; } else { return true; } }
Gentlemen experts, would it be correct to explain it in this way? :
Of course not.
Consider what you would have to code in the case there is no function but a
predefined value. For instance, you want to disable the submission of form
input.
You could have:
var submissionBlock = false;
element.onsubmi t = return submissionBlock ;
Meaning: pass the value of submissionBlock to the form.
This is a syntax error instead: `return' has been used outside of a function.
If you had
element.onsubmi t = submissionBlock
it would assign the value of submissionBlock to the property onsubmit of
element (which would not affect the form's excution).
Certainly not.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ximo |
last post by:
Hello, I want that the return sentence don't return anything, how can I do
it?. If i do only return it returns None, and pass don't run too.
Can anyone help me?, thanks.
XIMO
|
by: Michael Stevens |
last post by:
Probably the wrong wording but since I'm not a scripter I won't claim
to know what I'm talking about.
I got this script from www.htmlgoodies.com
<script language="JavaScript">
<!--
window.open ('photos01.html','photogallery',config='height=550,
width=750,toolbar=no, menubar=no, scrollbars=no, resizable=no,
location=no, directories=no,...
|
by: Mike Machuidel |
last post by:
Hi,
I'm a game developer programming mostly in C and ASM for about 7 years.
Today at work a colleague (a C++ programmer) yelled at me I'm a bad C
programmer because I use "return(0);" instead of "return 0;".
He explained that "return" is not a function but a stament, like I
didn't know already. The other colleagues also argreed with him...
|
by: LaEisem |
last post by:
On-the-job, I have "inherited" a lot of old C language software.
A question or two about when "casting" of null pointer constants
is needed has occurred during behind-the-scenes cleanup
of some of that software. That subject seems not to be addressed,
at least not directly, in the C FAQ where FAQ 5.2 seems most relevant.
References:
* C...
|
by: Greenhorn |
last post by:
Hi,
when a function doesn't specify a return type ,value what value is
returned. In the below programme, the function sample()is returning the
value passed to 'k'.
sample(int);
main()
{
int i = 0,j;
j = sample(0);
| |
by: vl106 |
last post by:
char* foo () {
return "abc";
}
I compiled the above code both with MSVC and GCC for PPC. The string
"abc" is generated as a global entity. Thus (1) foo doesn't return a
temporary
and (2) no deallocation is necessary.
What does the standard say about this? Is this a "feature" I can rely on on
|
by: Axel Bock |
last post by:
Hi all,
I am trying to get my head around what happens if I return a class
object from a function.
It seems C++ (MinGW) does not invoke the copy constructor if I do
something like this:
SomeObj foo()
{
SomeObj X;
|
by: Jon Slaughter |
last post by:
is there any way to simply add an attribute like feature to a
function/method definition?
say I create a function like
function Test()
{
//....
}
|
by: .rhavin grobert |
last post by:
guess you have the following classes...
___________________________________
class {
//..a couple of methods ...//
};
class A {
public:
//...//
B* GetB() // <- this we'll talk about
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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. ...
| |
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...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |