View Full Version : return false? return true??
vkidv
09-09-2002, 06:15 PM
hmmm
i dont know what this means. :mad:
and i would really like to know what and and example
please help :p
:D
Roy Sinclair
09-09-2002, 06:46 PM
Think in terms of return value. The return statement is used to exit a function and to optionally provide a return value from the function (in truth, all functions return a value but if you don't use the return statement to specify the value you just get what the interpreter decides to return).
Thus return true; and return false; are simple function exits returning a boolean value.
In use though, you'll see something like: onclick="afunctioncall(param1,param2); return false;". What may not be evident is that this code for an event is effectively a function declaration and when it exits a return value can be provided. The return value sent from such an event declaration is often used to control the processing of the event after the function. In the example I used above the return false; would cause the event to be cancelled and no further processing would occur.
Does that help?
boywonder
09-09-2002, 07:15 PM
another common use is to have a form tag something like this
<form action="somepage" method="post" onSubmit="return myfunction();">
so in myfunction you would have some code to check the user's input, and then decide whether or not to actually submit the form (return true), or cancel (return false) and alert the user to what's wrong. does that help?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.