admin管理员组文章数量:1410723
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?
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?
- Made a mistake saying "programmatic access" when I meant "edit" access. Thanks greyfade.. if that works, then easy peasy. – madcolor Commented Feb 27, 2009 at 0:59
3 Answers
Reset to default 5You can locate the submit button through the DOM (getElementByID()
or document.formname
e to mind) and then set the submit button's onsubmit
value to a function of your choice.
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.
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 function name.
本文标签: detectIs there a way to fire a javascript function on submit without onsubmit()Stack Overflow
版权声明:本文标题:detect - Is there a way to fire a javascript function on submit without onsubmit() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745023094a2638247.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论