The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
How to override onsubmit for custom validation
I want to override the onsubmit attribute of the form on the newthread page as I have added a few custom fields to it that I need to validate. However the onsubmit value will not change. Here's what I am doing -
Code:
var form = document.getElementsByTagName("form")[1]; form.onsubmit = 'override_submit()'; Code:
form.action= 'xyz'; |
#2
|
|||
|
|||
I'm not a js expert but it looks OK to me. How do you know it's not changing?
ETA: actually (after googling for answers), if you set it from js you might have to set it to a function and not a string. So you'd want: Code:
form.onsubmit = override_submit; |
#3
|
|||
|
|||
I've just tried that and it doesnt work either. I cant understand how the action attribute can be changed no problem yet the onsubmit attribute cant.
Can someone try adding the javascript Code:
var form = document.getElementsByTagName("form")[1]; form.onsubmit = override_submit; |
#4
|
|||
|
|||
I made this as a test and it works:
Code:
<html><head><title>Test</title> </head> <body> <form> <input type="submit"> </form> <script> function override_submit() { alert("It works!!"); } var form = document.getElementsByTagName("form")[0]; form.onsubmit = override_submit; </script> </body> </html> I used [0] instead of [1], but I thought maybe you used 1 because there was another form on the page. |
#5
|
|||
|
|||
Hi, I tried your test and it worked and then I noticed that even though it works the html view in firebug still shows the onsubmit function as the original function...
So I tried it again with vbulletin and it is calling the new function now, even tho firebug still shows the form's onsubmit as the old function. Dont kno if this is a bug with firebug but at least this is working now. Cheers mate. --------------- Added [DATE]1312334345[/DATE] at [TIME]1312334345[/TIME] --------------- Hmmm, one other thing...I need to declare the onsubmit in the form of Code:
onsubmit = 'return override_submit'; But it doesn't work when I use -- return -- and quotation marks. Any ideas? |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|