Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I am curious on how to interpret this same tutorial, but how can I use this to convert XML to PHP to display the stars. Tutorial Here

I cannot get the stars to fill up properly with the numbers I typed into my input that has a name of newrating.

Here is my HTML code :
HTML
 <div class="review-rate">
<pre lang="PHP">
   <php echo '<span class="stars"><span></span></span>'>
 </div>



Here is my JQuery code :

JavaScript
$(function() {          
            $('.submit-btn2').click(function() {
                $('p').html('<span class="stars">'+parseFloat($('input[name=newrating]').val())+'</span>');
                val = Math.round(val * 4) / 4; /* To round to nearest quarter */
                val = Math.round(val * 2) / 2; /* To round to nearest half */
                var size = Math.max(0, (Math.min(5, val))) * 16;
                $('span.stars').stars();
            });         
            $('.submit-btn2').click();
        });

        $.fn.stars = function() {
            return $(this).each(function() {
                $(this).html($('<span />').width(Math.max(0, (Math.min(5, parseFloat($(this).html())))) * 16));
            });
        }



Lastly, here is my PHP form:
PHP
    <form action="xmlprocessad.php" method="POST" id="myform">
      <div class="addRev-contain">
         <input type="text" name="newrating" class="rev-input" placeholder="# / 5 Stars"></input><br>
         <input type="submit" class="submit-btn2">
      </div>
</form>
Posted
Comments
Maciej Los 7-Mar-14 17:44pm    
What you mean by: "I cannot get the stars to fill up properly with the numbers I typed into my input"?
Have you any message error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900