Forum Moderators: open

Message Too Old, No Replies

Making input type=button checked?

         

nelsonm

5:36 am on Jan 12, 2011 (gmt 0)

10+ Year Member



Hi all,

I tried to make a html push button checked/highlighted by trying "document.getElementById("button").checked = true;" but Unlike <input type=(radio/checkbox) />, it appears that input type=button does not support the checked attribute.

Is there a way to use dom to either make the button checked or simulate the button being checked like it looks when the cursor is focused on it (the two tone color look) until the button is pressed again?

ProbablyMike

11:30 am on Jan 12, 2011 (gmt 0)

10+ Year Member



How can a button be checked? It can be clicked, but not checked.
Buttons have no checked attribute.

You could set the button to have focus(), works for me in Firefox 3 and IE8.

Another options change the colours via CSS.

nelsonm

6:06 pm on Jan 12, 2011 (gmt 0)

10+ Year Member



Although i know it's not supported and i would not use it in a production setting, you can actually add "checked=checked" to the button input tag in Firefox - and it works!

Basically, i want the button to stay highlighted when clicked until clicked again to unhighlight just as repeated clicking on a checkbox checks and unchecks it. Another example would be pressing an illuminated power button on a blu-ray player... when pressed, the button illuminates and stays illuminated until pressed again to turn it off.

Applying focus()to the button does not keep it highlighted while clicking other areas of the page.

I know that i can change the forground/background/border and so on... color of the default button through css, but unfortunately, doing so also has the unintended effect of changing the physical look of the button as well. All i want to do is change the color of the button without destroying the two tone and rounded edge look.

I'm guessing i'm going to have to create two tone image buttons to achieve the look i want.