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 ! ^^
- you can use
.is(":checked")
check if radio input checked or not. .prop('checked', true)
cannot used in condition statement doesn't return boolean result. used set status of radio button checked.
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
Post a Comment