>> -----Original Message----- >> From: S. Isaac Dealey [mailto:[EMAIL PROTECTED]] >> Sent: Sunday, December 15, 2002 11:04 PM >> To: CF-Talk >> Subject: Re: Mildly OT: JS, Form, Passing Vars >> >> >> > Also the onclick event may need to return true for the >> > form to actually submit. I didn't test this :) >> > onclick="setFormParams(this.form, 'complete'); return >> > true;" >> >> My understanding / experience is that an onclick event >> only >> prevents a form from submitting when it's in a submit >> button >> with specifically this syntax: >> >> onclick="return myfunction();" >> >> and the function call returns false. ( Or you put return >> false; on the end of the attribute, although I can't >> imagine >> why you'd want to ) ...
> That works - but only if the button is pressed. > Submitting the form > some other way like pressing the "enter" key) doesn't fire > an event on > the submit button. > For this reason you should trap such things at the form > level (using > onSubmit() and returning false should work). > If you're secure in your environment (MSIE 4+ will do > this) you can also > take advantage (if the environment supports it) of event > bubbling and > trap the submit at some higher level (like the body tag or > a table tag). > This works well if you have many small forms on a page and > want to trap > their submits for some reason. Good point... I frequently avoid placing a submit button on a form, which forces the user to actually mouse-click a submit button or tab to select it and press enter and submit the form with the onclick event of that <button> or <input type="button"> There could be browsers around that submit on an enter-key press anyway, but afaik IE and NS both require you to actually press a button if there's no <input type="submit"> in the form. And I do use the onsubmit() event when I have a submit button in the form -- sorta blew through my response last night. Syntax should be the same for onsubmit() as for onclick() tho. I've never done anything with the event bubbling in IE -- I did once need to create a page that would warn users that their changes would be lost if they didn't press a confirmation button ( the app required the ability to allow users to edit a list of items, but wanted to limit the amount of editing that would be done for purposes of consistency and try to force the users to think a little bit about what they were doing before they did it ). I never could figure out how to stop a new page request (from a link, etc.) from the onunload() event of the page, which sucked, but because I could be reasonably assured that there weren't other forms on the page, that none of the links had existing onclick events and that users would more likely than not be moving to a new page from a link on the current page, I ended up doing this: for (var x = 1; x < document.links.length; x++) { document.links[x].onclick = "return confirm('Your changes will be lost.\n\nDo you wish to continue?');"; } I don't really recommend this -- it's just what I could come up with at the time. It was an Opera friendly environment, so event bubbling was far from an option. s. isaac dealey 954-776-0046 new epoch http://www.turnkey.to lead architect, tapestry cms http://products.turnkey.to certified advanced coldfusion 5 developer http://www.macromedia.com/v1/handlers/index.cfm?ID=21816 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq This list and all House of Fusion resources hosted by CFHosting.com. The place for dependable ColdFusion Hosting.