By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,997 Members | 1,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,997 IT Pros & Developers. It's quick & easy.

invalid return error...calling function?

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.