invalid return error...calling function?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • evan.cooch@NOSPAMcornell.edu

    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="javasc ript: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="javascrip t:return CheckIt(AbsForm )">
    <img src="images/submit_button.g if" 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:retu rn 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...
  • Lee

    #2
    Re: invalid return error...calling function?

    evan.cooch@NOSP AMcornell.edu said:[color=blue]
    >
    >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="javas cript: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="javascrip t:return CheckIt(AbsForm )">
    ><img src="images/submit_button.g if" border=0></a>
    >
    >
    >the error message I get is:
    >
    >"invalid return"[/color]

    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="javascrip t:'<html><body> '+(new Date()).toLocal eString()+'</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"

    Comment

    • evan.cooch@NOSPAMcornell.edu

      #3
      Re: invalid return error...calling function?

      THanks very much!

      My followup embedded below:

      [color=blue]
      >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
      >specificatio n 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="javascri pt:'<html><body >'+(new Date()).toLocal eString()+'</body></html>'"
      >
      >Whatever value you're returning isn't valid HTML (or void, which means
      >to leave the current page unchanged).[/color]

      OK, so why then DOES the following worK

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

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

      [color=blue]
      >
      >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"[/color]


      I'll do that, but would be interested in your answer to why the href
      approach works in some cases, but not others.

      Comment

      • Lee

        #4
        Re: invalid return error...calling function?

        evan.cooch@NOSP AMcornell.edu said:[color=blue]
        >
        >THanks very much!
        >
        >My followup embedded below:
        >
        >[color=green]
        >>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
        >>specificati on 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="javascr ipt:'<html><bod y>'+(new Date()).toLocal eString()+'</body></html>'"
        >>
        >>Whatever value you're returning isn't valid HTML (or void, which means
        >>to leave the current page unchanged).[/color]
        >
        >OK, so why then DOES the following worK
        >
        ><a href="javascrip t:void(document .TheForm.reset( ))">
        ><img src="images/start_over.gif" ></a>
        >
        >It uses href, but it executes the javascript just as intended.[/color]

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

        Comment

        • evan.cooch@NOSPAMcornell.edu

          #5
          Re: invalid return error...calling function?

          [color=blue][color=green]
          >>OK, so why then DOES the following worK
          >>
          >><a href="javascrip t:void(document .TheForm.reset( ))">
          >><img src="images/start_over.gif" ></a>
          >>
          >>It uses href, but it executes the javascript just as intended.[/color]
          >
          >Because the Javascript expression evaluates to void, which means to
          >leave the current page unchanged.[/color]


          Got it - thanks....

          Comment

          Working...