Disable Buttons
Hi
I hope someone can help me with this little niggle.
I have a page with a text box, and 7 buttons. One for each day of the week like
[--------Days-------]
[Mon][Tue][Wed][Thu][Fri][Sat][Sun]
When the user presses a day, it's added to the text box (days). But the user is allowed to only submit that day once.
What I'd like to be able to do is once a button has been clicked, is to disable it so the user can't pick it again.
I've found code to disable a button, but i'm having problems making it work for them all.
Anyone have an idea?
Many thanks
Visual
jdiben posted this at 17:32 — 22nd January 2005.
He has: 14 posts
Joined: Jan 2005
The following code should help you out. Be sure to name your form and buttons.
<form method=post action="" name="days">
<input type="button" value="button1" name="button1"
onclick="javascript: document.days.button1.disabled=true">
<input type="button" value="button2" name="button2"
onclick="javascript: document.days.button2.disabled=true">
<input type="button" value="button3" name="button3"
onclick="javascript: document.days.button3.disabled=true">
</form>
Joe
Joe
GimmeItNow.com
Gift Registry For Any Occassion
CptAwesome posted this at 00:38 — 23rd January 2005.
He has: 370 posts
Joined: Dec 2004
that works, but you might want to change the "onclick" to "onmouseup" though.
jdiben posted this at 03:20 — 23rd January 2005.
He has: 14 posts
Joined: Jan 2005
If you change to "onmouseup" the javascript will only be executed by mouse clicks and not by tabbing to the buttons and pressing "enter" or "space". Is there a reason that you should use "onmouseup" instead of "onclick".
Joe
Joe
GimmeItNow.com
Gift Registry For Any Occassion
Visual posted this at 02:48 — 23rd January 2005.
They have: 3 posts
Joined: Mar 2002
bah ! ... as simple as that! ... i really need to catch up more on JavaScript...
Thanks for the code/tips guys!
Visual
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.