-1

Radio button i have

For yes:

html+='<input type="radio" id="engyes'+val.id+'" name="eradios['+val.id+']" value="'+val.id+'" data-for="yes" onclick="changeinother(this.id);" class="form-control">';

For no :

<input type="radio" id="engno'+val.id+'" name="eradios['+val.id+']" value="0" data-for="no" onclick="changeinother(this.id);" class="form-control">';

On click change radio background color for yes Green and For no Red

script what i am using to change color

<script type="text/javascript">
  function changeinother(radioid)
  {
  var curr=$('#'+radioid).attr('data-for');
  if(curr=='no'){
     $('input[type=radio]:checked').css('background-color','red');
  }
  }
</script>

I tried this but its not working with my code what i am doing wrong here can anyone please tell ??

Kidus
  • 1,785
  • 2
  • 20
  • 36
Sneha
  • 53
  • 7

2 Answers2

1

You can not set background color to the plain html radio input, you can use Custom Radiobutton

programtreasures
  • 4,250
  • 1
  • 10
  • 29
0

Working Demo - http://jsfiddle.net/6jt8h/

<div id= "genre">
What do you bust a move to?
<br>
<br>
<form name="music" method="post" action="">
<p>
<input type="radio" name="music" value="radio" onClick="changeColour('b')">Blues
<br>
<input type="radio" name="music" value="radio" onClick="changeColour('r')">Rock
<br>
<input type="radio" name="music" value="radio" onClick="changeColour('p')">Pop
<br>
</form>
</div>

window.changeColour = function(value)
{
alert(value);
var color = document.body.style.backgroundColor;
switch(value)
{
    case 'b':
        color = "#FF0000";
    break;
    case 'r':
        color = "#0000FF";
    break;
    case 'p':
        color = "#FF00FF";
    break;
}
document.body.style.backgroundColor = color;
}