Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > dynamic function not attaching to event

Reply
Thread Tools

dynamic function not attaching to event

 
 
Toby Miller
Guest
Posts: n/a
 
      05-03-2005
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

 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      05-15-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VS 2005..Attaching event handlers hharry ASP .Net 2 05-21-2007 04:23 PM
attaching an event to ServerValidate =?Utf-8?B?RGF2ZQ==?= ASP .Net 1 05-15-2007 08:38 PM
Reading COM port - Attaching an event or interrupt for arrival of new data? Per C++ 1 04-18-2005 10:34 PM
Attaching Event With Parameters to image control created dynamicll =?Utf-8?B?V2ViTWF0cml4?= ASP .Net 6 12-07-2004 03:21 PM
Attaching to event in container object Cowboy \(Gregory A. Beamer\) ASP .Net 2 10-28-2003 08:03 PM



Advertisments