Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using css to disable a button

Status
Not open for further replies.

Ovatvvon

Programmer
Feb 1, 2001
1,514
US
Hello all,

I'm obviously doing something wrong. I thought for sure there was a way to disable a button using css, but could not find the attribute on msdn, and have not been able to figure out a syntax that will work. Does anyone out there know?

This is one example that I've tried so far:
Code:
<input type="button" id="item1" name="btnItem1" style="document.getElementById('item1').enabled='false';">


-Ovatvvon :-Q
 
disable a button using CSS? you cannot perform an action in CSS - it's used for stylistic purposes only.

i suppose you could position an element OVER the button to prevent a user from clicking on the button, or you could just hide the button completely.



*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Code:
<input type="button" id="item1" name="btnItem1" disabled="disabled" />
You were doing something wrong. You were adding style information (how it looks) and putting scripting into it (how it behaves). What you wanted to do, you could accomplish with one of the events, but it is better this way.
 
Vragabond,
that would require hardcoding it, which is what I was trying to avoid. I actually want this to be dynamic, and so was going to be making additional changes to do so. Do you know how to make it dynamically change to be enabled/disabled?

cLFlaVA (or anyone),
do you know if it is possible via Javascript? I just thought for-sure there was some way to alter that setting dynamically.

-Ovatvvon :-Q
 
What you're writing is JavaScript. Also, although I believe I HAVE seen 'enabled' somewhere, the universally acceptable property is 'disabled' (which you would set to true, of course).

What are you trying to do? Will this button be enabled/disabled on and off based on some other event? If so, that's JavaScript.

...or will it just be disabled all the time? If that's the case, add disabled='disabled' to the INPUT tag. Of course, if that WAS the case, I'm sure you wouldn't be making it a button.

Feel free to head on over to the JavaScript forum (forum216) for all your JavaScript needs!

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
P.S., when I typed my response, no one else had responded yet, but the server was down or something... Anyway, that's why it looks like I hadn't read other people's contributions prior to my post.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
[blush]


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top