dynamic function not attaching to event

T

Toby Miller

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:

http://www.tobymiller.com/js/validation.htm

Any ideas?

-tm
 
T

Thomas 'PointedEars' Lahn

Toby said:
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.

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

Yes, but there is no result, e.g. the return value of that function is
`undefined'.

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="return 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top