I am looking to write a javascript function that will fire when a user submits a form, however I do not have edit access to the submit button so that I can add the onsubmit function. I am able to add a <script>
tag, so if I can detect the submit, then I can execute my code. Anyone know how to do this?
views:
770answers:
3
+4
A:
however I do not have programmatic access to the submit button so that I can add the onsubmit function
How is that possible? If you're executing JavaScript on page, you have access to the entire DOM.
Kevin
2009-02-27 00:53:45
Because I'm dealing with a shopping cart which only allows me to drop content in. The "submit" button is simply a checkbox in the cart admin interface.
madcolor
2009-02-27 00:55:35
It doesn't matter. If the javascript is executing in that page, it has access to the DOM. Does the submit button have an id that you can use to retrieve it?
Kevin
2009-02-27 00:58:22
If you can drop in javascript, then you can add your code to the button.
jdigital
2009-02-27 00:58:25
+4
A:
You can locate the submit button through the DOM (getElementByID()
or document.formname
come to mind) and then set the submit button's onsubmit
value to a function of your choice.
greyfade
2009-02-27 00:57:27
A:
You can use the attachEvent or addEventListener to attach an event for an DOM Object.
e.g. element = document.getElementById('submitButtonId'); element.addEventListener('click',doSomething,false);
while "doSomething" is the fucntion name.
Murvinlai
2009-02-27 01:13:09