set event handlers in external script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian

    #1

    set event handlers in external script

    Is it possible to set form event handlers in an external script (via
    onload)? I've used a script to set onmouseover, but I get errors when I
    try to set onreset from an external .js file with this function:

    function addValidationTo Form() {
    document.forms[0].onreset = return confirm('reset form?');
    document.forms[0].onsubmit = validateOnSubmi t();
    }

    --
    Brian (remove ".invalid" to email me)

  • Lee

    #2
    Re: set event handlers in external script

    Brian said:[color=blue]
    >
    >Is it possible to set form event handlers in an external script (via
    >onload)? I've used a script to set onmouseover, but I get errors when I
    >try to set onreset from an external .js file with this function:
    >
    >function addValidationTo Form() {
    > document.forms[0].onreset = return confirm('reset form?');
    > document.forms[0].onsubmit = validateOnSubmi t();
    >}[/color]


    Both of those attributes should be function references.
    return confirm('reset form?')
    is not a function reference, or even a valid expression.
    Your second assignment would execute validateOnSubmi t() immediately
    and assign the returned value to the onsubmit attribute.

    document.forms[0].onreset = function(){retu rn confirm('reset form?')};
    document.forms[0].onsubmit = validateOnSubmi t;

    Comment

    • Brian

      #3
      Re: set event handlers in external script

      Lee wrote:
      [color=blue]
      > Brian said:
      >[color=green]
      >>function addValidationTo Form() {
      >> document.forms[0].onreset = return confirm('reset form?');
      >> document.forms[0].onsubmit = validateOnSubmi t();
      >>}[/color]
      >
      >
      > return confirm('reset form?')
      > is not a function reference[/color]

      I tried to copy what was in the onReset attribute. :-/
      [color=blue]
      > Your second assignment would execute validateOnSubmi t() immediately[/color]

      So I noticed. ;-)
      [color=blue]
      > document.forms[0].onreset = function(){retu rn confirm('reset form?')};
      > document.forms[0].onsubmit = validateOnSubmi t;[/color]

      That solved it. Thanks for providing the help I needed.

      --
      Brian (remove ".invalid" to email me)

      Comment

      Working...