java - Star Rating in javascript value comming from backend -
i need star rating. in page value comming java/backend.(i need javascript or prototypejs solution.)
eg: if value come 1 must show 1 star.
if value come 2 must show 2 star , on...till 5
this whole thing happening in dynamic . using below code, not create id.
javascript
function display() { var x = "yr"; show_image(x ,2) ; } function show_image (id,number) { var x = number; var y = id; (var =0; i<x; i++){ var img = document.createelement("img"); img.src = "stars.png"; document.getelementbyid(y).appendchild(img); } }
thanks help.
//just demo purpose function getrating() { var number = prompt("enter rating?"); if(number *= 1 > 0 && number <=5) { show_image('yr', number); } else { alert("enter valid rating, greater 0"); } } function show_image (id,number) { document.getelementbyid(id).innerhtml = ''; (var =0; i<number; i++){ var img = document.createelement("img"); img.height=10; img.src = "http://icons.iconarchive.com/icons/custom-icon-design/flatastic-2/512/star-full-icon.png"; document.getelementbyid(id).appendchild(img); } }
your code has no issue, working fine. simplest way call function java servlet/jsp response is, added <script>show_image('_some_id_', number_of_star)</script>
add comment, if have query, or if understanding of problem not correct.
Comments
Post a Comment