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

colors

Status
Not open for further replies.

killerg

Programmer
Dec 2, 2006
15
CY
can i assign a color to the values of
my radio buttons ?

 
The best you can do is place a background-color around the button.

[monkey][snake] <.
 
Filling in the white center of the radio button is not possible with javascript or css.

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
no i dont want to change the font.

for example i have the radio buttons with the
names violet and daisy. When i choose violet and i click to a button the color of the world violet to have a different color than the usual black color.
 
Here's how I'd tackle it. The text off to the side of your radio buttons is not a property of the radio button. So unless you set up your HTML so that each radio button and it's associated text are enclosed by a readily obtainable element, you won't be able to get at it.

Solution:
Wrap the buttons and their text in some DIV tags so that each radio button and the text you want to change are enclosed by one DIV tag. And all of those tags are enclosed by another tag.

Play with this one if you like:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Colour Demo</title>
<script type="text/javascript" language="javascript">
function toggleColour(objRadio){
	var baseColour = "#000000";
	var selectedColour = objRadio.value;
	var parentElement = (objRadio.parentElement == null ? objRadio.parentNode : objRadio.parentElement);
	var topElement = (parentElement.parentElement == null ? parentElement.parentNode : parentElement.parentElement);
	var allElements = topElement.getElementsByTagName("div");
	//Loop through all of the radio containing elements
	for(var i = 0; i < allElements.length; i++){
		//And set them to black.
		allElements.item(i).style.color = baseColour;
	}
	//Then set the one that contains this radio to it's chosen colour
	parentElement.style.color = selectedColour;
}
</script>
</head>

<body>
<div>
<div><input type="radio" value="#FF0000" name="colourSelection" onclick="toggleColour(this);" />Red</div>
<div><input type="radio" value="#00FF00" name="colourSelection" onclick="toggleColour(this);" />Green</div>
<div><input type="radio" value="#0000FF" name="colourSelection" onclick="toggleColour(this);" />Blue</div>
</div>
</body>
</html>

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Enable Apps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top