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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkboxes and Radio buttons 1

Status
Not open for further replies.

Jaheel22

Technical User
Jul 14, 2004
84
US
Hi guys

Is there any way to make radio button and checkboxes un-editable or not editable by the user. Right now i'm using the "disabled" attribute but it changes the color to gray.
Here is the syntax

<input type="radio" name="PltTypeCD" disabled checked>
but if do
<input type="text" name="PrtldCmtQty210" readonly="aaa">, then text box color stays white and this box is uneditable.
But problem is readonly attribute does not work in case of radio buttons or checkboxes.

Any idea ?

Thanks indeed
 

If you don't want to use the disabled attribute (which I would recommend sticking with - even with the colour change), you could try using JS to detect when the radio button has been clicked on, and then set some other radio button, effectively un-clicking the one that has just been set.

Something like this:

Code:
<html>
<head></head>
<body>
	<form>
		<input type="radio" name="myRadio" value="wibble">
		<input type="radio" name="myRadio" value="bibble" onclick="this.form.elements['myRadio'][0].checked = true;">
		<input type="radio" name="myRadio" value="wibbly">
		<input type="radio" name="myRadio" value="bibbly">
	</form>
</body>
</html>

Whenever the second radio button is clicked, it "auto-clicks" the first one. Of course, you could keep track of which was the last one clicked, and set that back to "checked", for consistency.

Hope this helps,
Dan
 
Firstly, why do you want to do this? It's actually quite useful to the user to see that a box is "greyed out" so they know they can't click on it.

A sure-fire way of doing it would be to just use an image of a checked/unchecked box, with an <input type="hidden"> element to hold the actual value.

-- Chris Hunt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top