The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
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. |
#2
|
||||
|
||||
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> |
#3
|
||||
|
||||
Thanks I'll try it out and let you know how it worked.
|
#4
|
||||
|
||||
<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>
|
#5
|
||||
|
||||
Works fine for me. Post your code and what browser you're using to test it.
|
#6
|
||||
|
||||
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> 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. |
#7
|
||||
|
||||
Have it disabled by default-- see my example.
|
#8
|
||||
|
||||
<font color="darkgreen">Ah, I missed this part disabled="disabled"
Thanks.</font> |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|