470,648 Members | 1,608 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,648 developers. It's quick & easy.

prevent form submission with dynamic onsubmit?

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.

Oct 2 '05 #1
1 2550
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 2 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by middletree | last post: by
2 posts views Thread by Pamela Chatterjee | last post: by
27 posts views Thread by Chris | last post: by
2 posts views Thread by ddog | last post: by
6 posts views Thread by Stanimir Stamenkov | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.