prevent form submission with dynamic onsubmit?

N

nybble

Hello,

I'm trying to create a form whose onsubmit returns false if the form
should not be submitted. Normally this type of thing works great for
me:

<form onsubmit="return somefunction()">

where somefunction returns false. But I'm trying to do some thing where
in some
script block, the function gets added:

form.attachEvent("onsubmit", function () { return somefunction()
});

(not worrying about crossplatformosity, sorry). But that doesn't work,
the form is always submitted. Is there something else I need to be
doing to make this happen?

All help is appreciated.
 
R

Randy Webb

nybble said the following on 10/2/2005 1:08 PM:
Hello,

I'm trying to create a form whose onsubmit returns false if the form
should not be submitted. Normally this type of thing works great for
me:

<form onsubmit="return somefunction()">

where somefunction returns false. But I'm trying to do some thing where
in some
script block, the function gets added:

form.attachEvent("onsubmit", function () { return somefunction()
});

refToForm.onsubmit = new Function(){ return somefunction()}

attachEvent is known to be buggy in some situations. Ditch it and access
what you want directly.
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top