Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-02-2011, 09:44 PM
ltwinnerr ltwinnerr is offline
 
Join Date: Feb 2010
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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()';
And nothing changes. However if I try to change the action attribute of the form it works no problem.
Code:
form.action= 'xyz';
So any ideas on what I am doing wrong?
Reply With Quote
  #2  
Old 08-02-2011, 10:45 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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;
Reply With Quote
  #3  
Old 08-02-2011, 11:33 PM
ltwinnerr ltwinnerr is offline
 
Join Date: Feb 2010
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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;
to their newthread.php page and see if they can override the submit handler. Because this has me stumped.
Reply With Quote
  #4  
Old 08-02-2011, 11:40 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 08-03-2011, 12:01 AM
ltwinnerr ltwinnerr is offline
 
Join Date: Feb 2010
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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';
So that I can stop the form from getting sent if the validation fails.


But it doesn't work when I use -- return -- and quotation marks.

Any ideas?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:39 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03595 seconds
  • Memory Usage 2,200KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete