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

invalid return error...calling function?

Greetings.

Suppose I have some function called "CheckIt" - some function to
validate form data before submitting it to e CGI script. Pretend the
name of the form is "TheForm".

If I use the following code, everything work perfctly:

<Input type=button VALUE="Submit your form"
onClick="javascript:return CheckIt(TheForm)">

But, if I try to associate the submission with a graphic (call it
"submit_botton.gif"), using the following, I get an error:

<a href="javascript:return CheckIt(AbsForm)">
<img src="images/submit_button.gif" border=0></a>
the error message I get is:

"invalid return"

Using the Javascript console in Mozilla, it points to line 1, which is
indicated to be

javascript:return CheckIt(AbsForm)
I've tried several things, to no avail. I'm puzzled, because I've used
similar approaches (to associating functions with images), without any
problems.

Any suggestions? Pointers to the "obvious mistake"? :-)

Thanks in advance...
Jul 20 '05 #1
4 6846
Lee
ev********@NOSPAMcornell.edu said:

Greetings.

Suppose I have some function called "CheckIt" - some function to
validate form data before submitting it to e CGI script. Pretend the
name of the form is "TheForm".

If I use the following code, everything work perfctly:

<Input type=button VALUE="Submit your form"
onClick="javascript:return CheckIt(TheForm)">

But, if I try to associate the submission with a graphic (call it
"submit_botton.gif"), using the following, I get an error:

<a href="javascript:return CheckIt(AbsForm)">
<img src="images/submit_button.gif" border=0></a>
the error message I get is:

"invalid return"


There is a major difference between the value of an onclick attribute
and the value of an href attribute. The onclick attribute is expected
to be executable code.
The token "javascript:", if present, is read as either a language
specification or as a label, depending on what the browser is expecting.

On the other hand, the href attribute is supposed to be an URI.
The token "javascript:", if present, is read as a protocol name.

The javascript [pseudo]protocol means that the browser should evaluate
the javascript expression following the colon, and use its value as
the new contents of the page, as in:

href="javascript:'<html><body>'+(new Date()).toLocaleString()+'</body></html>'"

Whatever value you're returning isn't valid HTML (or void, which means
to leave the current page unchanged).

In general, don't use the javascript: protocol. Use the onclick event
handler of the link, and return false, so the link isn't followed.

You should also investigate these concepts:
onSubmit
input type="submit"
input type="image"

Jul 20 '05 #2
THanks very much!

My followup embedded below:

There is a major difference between the value of an onclick attribute
and the value of an href attribute. The onclick attribute is expected
to be executable code.
The token "javascript:", if present, is read as either a language
specification or as a label, depending on what the browser is expecting.

On the other hand, the href attribute is supposed to be an URI.
The token "javascript:", if present, is read as a protocol name.

The javascript [pseudo]protocol means that the browser should evaluate
the javascript expression following the colon, and use its value as
the new contents of the page, as in:

href="javascript:'<html><body>'+(new Date()).toLocaleString()+'</body></html>'"

Whatever value you're returning isn't valid HTML (or void, which means
to leave the current page unchanged).
OK, so why then DOES the following worK

<a href="javascript:void(document.TheForm.reset())">
<img src="images/start_over.gif"></a>

It uses href, but it executes the javascript just as intended.


In general, don't use the javascript: protocol. Use the onclick event
handler of the link, and return false, so the link isn't followed.

You should also investigate these concepts:
onSubmit
input type="submit"
input type="image"

I'll do that, but would be interested in your answer to why the href
approach works in some cases, but not others.
Jul 20 '05 #3
Lee
ev********@NOSPAMcornell.edu said:

THanks very much!

My followup embedded below:

There is a major difference between the value of an onclick attribute
and the value of an href attribute. The onclick attribute is expected
to be executable code.
The token "javascript:", if present, is read as either a language
specification or as a label, depending on what the browser is expecting.

On the other hand, the href attribute is supposed to be an URI.
The token "javascript:", if present, is read as a protocol name.

The javascript [pseudo]protocol means that the browser should evaluate
the javascript expression following the colon, and use its value as
the new contents of the page, as in:

href="javascript:'<html><body>'+(new Date()).toLocaleString()+'</body></html>'"

Whatever value you're returning isn't valid HTML (or void, which means
to leave the current page unchanged).


OK, so why then DOES the following worK

<a href="javascript:void(document.TheForm.reset())">
<img src="images/start_over.gif"></a>

It uses href, but it executes the javascript just as intended.


Because the Javascript expression evaluates to void, which means to
leave the current page unchanged.

Jul 20 '05 #4
OK, so why then DOES the following worK

<a href="javascript:void(document.TheForm.reset())">
<img src="images/start_over.gif"></a>

It uses href, but it executes the javascript just as intended.


Because the Javascript expression evaluates to void, which means to
leave the current page unchanged.

Got it - thanks....
Jul 20 '05 #5

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

Similar topics

8
by: Glenn A. Harlan | last post by:
Why am I receiving the below error when calling - Path.GetTempFileName() The directory name is invalid. Description: An unhandled exception occurred during the execution of the current web...
30
by: Tim Johansson | last post by:
I'm new to C++, and tried to start making a script that will shuffle an array. Can someone please tell me what's wrong? #include <iostream.h> #include <string.h> int main () {...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
2
by: Patrick Olurotimi Ige | last post by:
Why do i get "Invalid attempt to FieldCount when reader is closed" Is the problem the way the datareader reads data as opposed to a dataset? When trying to compile this code:- Dim reader As...
6
by: KWienhold | last post by:
I'm currently working on a project in C# (VS 2003 SP1, .Net 1.1) that utilizes IStream/IStorage COM-Elements. Up to now I have gotten everything to work to my satisfaction, but now I have come...
5
by: chrisstankevitz | last post by:
Hi, Q1: Is there a way to make a template function that works only for specific types which produces a compiler error if used with an invalid type? Q2: If not, how do people deal with this...
25
by: dennijr | last post by:
ok, shell always used to be easy for me, now its starting to get annoying cause i dont know wats wrong heres the simplist code possible: Private Sub IExplorer_Click() a = Shell("C:\Program...
10
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
21
by: rashgang | last post by:
no check box selected when i gave delete all link the error is coming <?php include "includes/connection.php"; include "includes/Functions_category.php"; include...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
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
tracyyun
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...
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,...

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.