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

Reply
 
Thread Tools Display Modes
  #1  
Old 10-27-2007, 08:04 AM
RobDog888's Avatar
RobDog888 RobDog888 is offline
 
Join Date: Apr 2007
Location: Degabah Swamp
Posts: 293
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Disable/Enable Button

I need to disable a form button until the member checks a checkbox. Since the form is created in template code I am unsure if it needs to be coded in the php fle or if it really can be done in the template code. Its late right now so maybe I am just missing something simple

Thanks for any help.
Reply With Quote
  #2  
Old 10-27-2007, 03:49 PM
Analogpoint's Avatar
Analogpoint Analogpoint is offline
 
Join Date: Feb 2007
Posts: 656
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
<form action="x" method="post" id="myform">
<textarea name="text"></textarea>
<label><input name="check" type="checkbox" onchange="handle_button_state();" /> Blah</label>
<input type="submit" disabled="disabled" name="sub" />
</form>
<script type="text/javascript">
function handle_button_state()
{
    var el = document.getElementById('myform');
    if (el)
    {
        if (el.check.checked)
        {
            el.sub.disabled = '';
        }
        else
        {
            el.sub.disabled = 'disabled';
        }
    }
}
</script>
Reply With Quote
  #3  
Old 10-27-2007, 05:03 PM
RobDog888's Avatar
RobDog888 RobDog888 is offline
 
Join Date: Apr 2007
Location: Degabah Swamp
Posts: 293
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks I'll try it out and let you know how it worked.
Reply With Quote
  #4  
Old 10-28-2007, 06:38 PM
RobDog888's Avatar
RobDog888 RobDog888 is offline
 
Join Date: Apr 2007
Location: Degabah Swamp
Posts: 293
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<font color="DarkGreen">Hmm, no dice. Button stil enabled and checking the checkbox doesnt change anything. I verified the id of the form and the name of the checkbox and submit button. Also, the event onchange addition to the checkbox element.</font>
Reply With Quote
  #5  
Old 10-29-2007, 02:41 AM
Analogpoint's Avatar
Analogpoint Analogpoint is offline
 
Join Date: Feb 2007
Posts: 656
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Works fine for me. Post your code and what browser you're using to test it.
Reply With Quote
  #6  
Old 10-29-2007, 06:32 AM
RobDog888's Avatar
RobDog888 RobDog888 is offline
 
Join Date: Apr 2007
Location: Degabah Swamp
Posts: 293
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just figured out that it doesnt work until it looses focus and requires you to check the checkbox/uncheck/recheck it in order to have it get in sync.

I have tested it on IE6 and IE7 so far with IE 6 only requiring the loss of focus one time.

Code:
<form enctype="multipart/form-data" id="upload">
'...
'...
<input type="checkbox" name="acceptterms" value="0" id="terms" onchange="handle_button_state();" />
'...
'...
<input type="submit" class="button" name="sbutton" id="{$editorid}_save" value="$vbphrase[submit]" accesskey="s"  tabindex="1" />
</form>

<script type="text/javascript">
function handle_button_state()
{
    var el = document.getElementById('upload');
    if (el)
    {
        if (el.acceptterms.checked)
        {
            el.sbutton.disabled = '';
        }
        else
        {
            el.sbutton.disabled = 'disabled';
        }
    }
    else
    {
        alert('blah');
    }
}
</script>
--------------- Added [DATE]1193648996[/DATE] at [TIME]1193648996[/TIME] ---------------

I changed it to the onclick event and it works better and also added the onblur and onfocus but I cant get it to disable the submit button on the first time page load? I used onload but nada.
Reply With Quote
  #7  
Old 10-29-2007, 02:37 PM
Analogpoint's Avatar
Analogpoint Analogpoint is offline
 
Join Date: Feb 2007
Posts: 656
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have it disabled by default-- see my example.
Reply With Quote
  #8  
Old 10-29-2007, 04:10 PM
RobDog888's Avatar
RobDog888 RobDog888 is offline
 
Join Date: Apr 2007
Location: Degabah Swamp
Posts: 293
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<font color="darkgreen">Ah, I missed this part disabled="disabled"

Thanks.</font>
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:18 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05137 seconds
  • Memory Usage 2,234KB
  • 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
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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