dynamic function not attaching to event

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

    #1

    dynamic function not attaching to event

    I have this form validation that I'm trying to build, but it's not
    working properly. A dynamic function to the onsubmit event for a form.
    the result of that function (true/false) should then be returned to
    pass or fail the submission of that form.

    What is happening is that in Firefox and IE returning false doesn't
    stop the form submission. In IE the dynamic function just doesn't work.
    If I attach a smaller dynamic function to the form onsubmit handler
    then it does work.

    Here's the problem page:



    Any ideas?

    -tm

  • Thomas 'PointedEars' Lahn

    #2
    Re: dynamic function not attaching to event

    Toby Miller wrote:
    [color=blue]
    > I have this form validation that I'm trying to build, but it's not
    > working properly. A dynamic function to the onsubmit event for a form.[/color]

    No. BTW: It is the `submit' event and the `onsubmit' event handler.
    [color=blue]
    > the result of that function (true/false) should then be returned to
    > pass or fail the submission of that form.[/color]

    Yes, but there is no result, e.g. the return value of that function is
    `undefined'.
    [color=blue]
    > [...]
    > http://www.tobymiller.com/js/validation.htm
    >
    > Any ideas?[/color]

    Your source code reads

    | <form name="myform" onsubmit="alert ('inline');"
    | action="/js/validation.htm" >

    After the document has been loaded, document.forms[0].onsubmit yields

    function onsubmit(event)
    {
    alert("inline") ;
    }

    You do not return a value to the `onsubmit' event handler, so submission
    will never be canceled. You have to use the `return' keyword within the
    event listener (here: the attribute value): return `false' to cancel
    submission, `true' to allow it. This is accomodated best by returning
    the result of a boolean function that is passed a reference to the form:

    <form ... onsubmit="retur n checkForm(this) ;">

    Note that if client-side scripting is not supported or is disabled, the
    form is submitted always, so additional server-side tests are a must.


    PointedEars

    Comment

    Working...