javascript - Rating module makes an input radio change -


i have rating module on webpage :

<div class="rating">    <label for="rate_1"class="glyphicon glyphicon-star"><input type="radio" id="rate_1" name="rating" value="1"></label>    <label for="rate_2"class="glyphicon glyphicon-star"><input type="radio" id="rate_2" name="rating" value="2"></label>    <label for="rate_3"class="glyphicon glyphicon-star"><input type="radio" id="rate_3" name="rating" value="3"></label>    <label for="rate_4"class="glyphicon glyphicon-star"><input type="radio" id="rate_4" name="rating" value="4"></label>    <label for="rate_5"class="glyphicon glyphicon-star"><input type="radio" id="rate_5" name="rating" value="5"></label> </div> 

and when click on 4th or 5th star, validated radio been checked in validation :

<ul class="validation">      <li class="success-hover"><label for="id_validation_1"><input class="success" type="radio" id="id_validation_1" name="validation"><i class="fa fa-check"></i>validated</label></li>      <li class="danger-hover"><label for="id_validation_2"><input class="danger" type="radio" id="id_validation_2" name="validation"><i class="fa fa-close"></i>rejected</label></li>      <li class="info-hover"><label for="id_validation_3"><input type="radio" id="id_validation_3" name="validation"><i class="fa fa-spinner"></i>partially completed</label></li>      <li class="warning-hover"><label for="id_validation_4"><input type="radio" id="id_validation_4" name="validation"><i class="fa fa-clock-o"></i>expired</label></li> </ul> 

i started jquery code :

if ($("input[name=rating][value=4]").prop('checked', true)||$("input[name=rating][value=5]").prop('checked', true)) {     $('.success').prop('checked', true); } else $('.success').prop('checked', false); 

but doesn't work... please me ! ^^

  1. you can use .is(":checked") check if radio input checked or not.
  2. .prop('checked', true) cannot used in condition statement doesn't return boolean result. used set status of radio button checked.

http://jsfiddle.net/02gocfr1/

jquery

$(function () {     $("input[name=rating]").change(function () {         if ($("input[name=rating][value=4]").is(":checked") || $("input[name=rating][value=5]").is(":checked")) {             $('.success').prop('checked', true);         } else $('.success').prop('checked', false);     }) }) 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -