I am new at javascript,and i was trying and trying with this but something is wrong,i wanna make the checked radio button red
and green if not checked,or black no matter,the essence is to make red the selected radio button,so if i select one it becomes red,this is what i know how to do but when i select another,make the radio button which i selected and became red,change it back to black,or green...i was trying with green to see better if anything works cuz the defaulth is black.So here is the code that does't works yet.
szc.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="query.js"></script>
<style>
.p1:hover
{
cursor:pointer;
}
</style>
</head>
<body>
<form action="szc.php" method="post">
<label class="p1"><input type="radio" class="p1" name="rg" id="id1" value="anything1"><font id="L1">This?</font></label>
<label class="p1"><input type="radio" class="p1" name="rg" id="id2" value="anything2"><font id="L2">Or this?</font></label>
<input type="submit"/></form>
</body>
</html>
query.js
<script type="text/javascript">
window.onload = function(){
var id1 = document.getElementById("id1");
id1.onclick = function(){
if( id1.checked == true)
{
id1.style.color = "rgb(255, 0, 0)";
}
if ( id1.checked == false)
{
id1.style.color = "rgb(0, 255, 0)";
}
}
var id2 = document.getElementById("id2");
id2.onclick = function(){
if( id2.checked == true)
{
L2.style.color = "rgb(255, 0, 0)";
}
else
{
L2.style.color = "rgb(0, 255, 0)";
}
}
};
</script>
Any help welcome!