By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,483 Members | 1,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,483 IT Pros & Developers. It's quick & easy.

prevent form submission with dynamic onsubmit?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.