0

The values do not pass for "id" and "rate_number" from database."ratingValue" is working, but "id" alert and "num" alert are not working.

Here is my PHP code.

$jsqla = mysql_query("select id,name,rate_score,rate_number,video_image from products where genre='$genre' limit 0,5");

if($jrowa['rate_number'] > 0){ 
  $ratea = $jrowa['rate_score'] / $jrowa['rate_number']; 
}else{ 
  $ratea = 0; 
}

Here is HTML code.

<div class="col-sm-2 portfolio-item" style="width: 20%;">

    <input class="rating form-control input-star-rate" name="rating" value="<?php echo $ratea; ?>" data-min="0" data-max="5" data-step="0.3" data-size="xs" style="display: none; text-align: center;"/>

</div>

Here is jQuery code.

$(function(){
    $(document).ready(function(e) {
        var $stars = $('.input-star-rate');

        $stars.bind('change', function() {
            var $this = $(this); 

            var ratingValue = $this.val();
            alert(ratingValue);

            var id = $this.attr("id");
            alert(id);

            var num = parseInt("$this.attr("rate_number")")+1;
            alert(num);
        });
    });
});

1 Answer 1

1

You didn't set the id attribute in the <input>.

$rateid = 0;
if($jrowa['rate_number'] > 0){ 
  $ratea = $jrowa['rate_score'] / $jrowa['rate_number']; 
  $rateid = $jrowa['id'];
}else{ 
  $ratea = 0; 
}

and:

<input class="rating form-control input-star-rate" id="<?php echo $rateid; ?>" name="rating" value="<?php echo $ratea; ?>" data-min="0" data-max="5" data-step="0.3" data-size="xs" style="display: none; text-align: center;"/>

Same for num (also doesn't work because you need to escape your quotes)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.