I am working on a website which basically has a form and includes a JS file: http://assets.sprint.degreesearch.org/assets/defaults.js?1311179143
What I am trying to do is dynamically apend an extra function on form submit (either via onclick function on submit button or via overwriting the functions included in the JS which gets triggered on form submit.
The problem is I am not very familier with Prototype.js and I am unable to execute a function on form submit. When its on onclick, it do triggers but immediately gets canceled by prototype i believe and its execution is stopped mid way.
The website in question is Step4 of http://sprint.degreesearch.org/collegefunnel website, where on Step4, while pressing Submit, I want to run a JS function which ideally takes around 200-300ms
Any pointers how I can unbind the event associated with mouse press and insert my dynamic script ahead of it and then bind back whatever has been bound by default
Prototype has a stopObserving
method for unbinding events. Depending on where the events are being bound, you could call stopObserving
on the form submit or the other elements' mouse events.
However, I don't think that's really the problem here. When you say you want to run a JS function which takes 200-300ms, I get confused. All JavaScript is synchronous, so the time it takes to execute is irrelevant. I suspect that there's an unstated requirement that the function in question is really an asynchronous call which may not return for that period of time.
In that case, what you really want to do is cancel the form submission. The form submission could be happening in one of two ways: either it's a natural form submission, or is in effect triggering an asynchronous call of some kind.
If it's a natural form submission, you can bind a new event handler to the form's submit action and call event.preventDefault()
to stop the browser from posting to the server. Then later, call .submit()
on the form to kick it off again.