Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>Styling disabled form elements?

Styling disabled form elements?

dep
03-16-2006, 06:58 PM
Someone told me that you do, actually, have the ability to style "disabled" form elements using javascript and CSS in IE (crossbrowser would be preferrable). Anyone know how to accomplish this? Help is much appreciated.

dep

jscheuer1
03-16-2006, 07:43 PM
You don't even need javascript for that:

<input type="text" style="font-size:.75em;border:2px dotted pink;" disabled>

But, if you want to use javascript to change the style of a disabled form element, you can do it in all of the usual ways you can for an enabled form element, one example:

<input id="test" type="text" style="font-size:.75em;border:2px dotted pink;" disabled>
<input type="button" onclick="document.getElementById('test').style.borderColor='black'">

dep
03-16-2006, 08:21 PM
Ahh.. cool!

mrhoo
03-16-2006, 08:35 PM
I bet you were looking for a pseudo- class; like an a:active style declaration.
I looked too. If you want your buttons and other items to LOOK disabled when they are disabled you have to do it yourself.
Something like:

function bigDis(boo, hoo){
var A=collect(hoo);
if(!boo || boo==='false')boo= false;
for(var i=0; i< A.length; i++){
var who= A[i];
disStyle(who,boo);
if(boo) who.disabled=true;
else who.disabled=false;
}
}


function disStyle(who,boo){
var c=(boo)? 'gray' : '';
if(boo) mrs(who,'textDecoration:line-through;cursor:wait;color:'+c);
else mrs(who,'cursor:pointer;textDecoration:none;color:'+c);
}
You can pass bigDis() one or an array of elements,
collect() makes sure they all exist before looping them.
mrs() is a shortcut to element.style[name]=value for multiple style changes.

jscheuer1
03-16-2006, 11:59 PM
mrs() is a shortcut to element.style[name]=value for multiple style changes.

Impressive mrhoo but, I'd like to meet mrs(who,boo), the function that is, not to mention collect().


 

TOP

Hyperthreading hurts s
HP sharpens blade PC l
Apple goes for Quad po
Itanium gets scaled do

For more info

HP sharpens blade PC l
Hyperthreading hurts s
can not call click() i
script does not work o
smart menu 
write to an html file 
FireFox doesn't recogn
Changing e.keyCode (e.
Clearing a range creat
UPDATE: My mouse over 

News Archive

onChange Help 
beforeload? vs onload.
Problem with document.
decreasing my javascri
Problem with \\ and \ 
how to stop scrolling?
Change Label Text Colo
Can I forward a page b
2 javascript functions
Validating a textbox 

Related stories:

Hiding an email address using javascript
Dropdown works in IE / Firefox but not Safari
Dynamically Populate Slideshow
Parameter Used to Update Formula
when to use return functionName on events
script that adds item to cart without going to shopping cart
problem with HTTPS
ebaY Category Picker doesn't work
window.opener problem when navigating away

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics