Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > invalid return error...calling function?

Reply
Thread Tools

invalid return error...calling function?

 
 
evan.cooch@NOSPAMcornell.edu
Guest
Posts: n/a
 
      01-05-2004
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...
 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      01-05-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) 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"

 
Reply With Quote
 
 
 
 
evan.cooch@NOSPAMcornell.edu
Guest
Posts: n/a
 
      01-05-2004
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.
 
Reply With Quote
 
Lee
Guest
Posts: n/a
 
      01-05-2004
(E-Mail Removed) 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.

 
Reply With Quote
 
evan.cooch@NOSPAMcornell.edu
Guest
Posts: n/a
 
      01-05-2004

>>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....
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
invalid character in base-64 string and invalid postback or callba kevin ASP .Net 0 01-16-2008 09:39 PM
How do fix: "Wrong number of arguments" / "invalid propert assignment"/ "Invalid argument" Java Guy Java 1 10-15-2006 08:31 PM
Invalid URI: There is an invalid sequence in the string. Error!! Patrick.O.Ige ASP .Net 1 07-02-2006 11:21 AM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
invalid@invalid.org Hank Sniadoch Computer Information 1 08-20-2004 11:24 AM



Advertisments