|go ahead... be a heretic|
Re: Attaching to Particular Form Submissionsby erroneousBollock (Curate)
|on Nov 28, 2007 at 06:28 UTC||Need Help??|
Great, you're attaching a handler to the 'load' event non-destructively, but then...
... you're destructively assigning to document.forms.onsubmit (clobbering any event handler that may already be present).
A better idea is to use the following:
(Any browser that implement neither addEventListener nor attachEvent is not worth supporting... the case for IE is already marginal ;)
If you must clobber a node's event handler 'slot' (eg: for reasons of event ordering) consider assigning an event handler that references the existing handler.
I want to target form submissions of a particular type, which is not always the second form.Each of the different kinds of page (usually) has a seperate nodeid (can be parsed from document.location.href).
As an example, the 'Comment On' page has node_id=3333 and takes a get parameter of the form parent=123456 to refer to the node being commented upon.
As mentioned above, you can also look for certain things in the document.body.innerHTML.
As an example, once you've submitted the 'Comment On' page (via preview) you can no-longer parse the parent nodeid from the document.location.href. It can be found in the main form of the (preview) page in a hidden input named 'note_parent_node'.
If XPath is available (either natively, or via a selector library like jQuery), I highly recommend it over using regular expressions to parse the contents of the pages.