How to call a php variable in jQuery? -


i want value of $jrowa['rate_score'] in php part num3 in jquery part. output nan alert in num3.

here php code.

$jsqla = mysql_query("select id,name,rate_score,rate_number,video_image products genre='$genre' limit 0,5");  $arate_num = $jrowa['rate_number'];     if($jrowa['rate_number'] > 0){          $ratea = $jrowa['rate_score'] / $jrowa['rate_number'];          $ratea2 = $jrowa['rate_score'];         $rateid = $jrowa['id'];         $ratenum = $jrowa['rate_number'];     }else{          $ratea = $jrowa['rate_score'];          $ratea2 = $jrowa['rate_score'];         $rateid = $jrowa['id'];         $ratenum = $jrowa['rate_number'];     } 

here html code.

<div class="col-sm-2 portfolio-item" style="width: 20%;">       <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;"/>  </div> 

here jquery code.

$(function(){     $(document).ready(function(e) {         var $stars = $('.input-star-rate');          $stars.bind('change', function() {             var $this = $(this); //  assign $(this) $this             var ratingvalue = $this.val();             alert(ratingvalue);             var ratingvalue2 = parsefloat(ratingvalue);             alert(ratingvalue2);              var ratingvalueprevious = parsefloat($(this).attr("value"));             var ratingvalueprevious2 = parsefloat(ratingvalueprevious);             alert(ratingvalueprevious2);              var id = $this.attr("id");             alert(id);              var phpvalue = "<?php echo $jrowa['rate_score']; ?>";             var num3 = parseint(phpvalue, 10);             alert(num3);          });     }); }); 

try this.

html code:

<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;" lats="<?php echo $rateid; ?>"/> 

then in jquery:

var vals = $(this).attr('lats');// store php variable value in jquery variable vals. 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -