Toby Miller wrote:
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'.
[...]
http://www.tobymiller.com/js/validation.htm
Any ideas?
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