Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6822065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:37:09+00:00 2026-05-26T21:37:09+00:00

I’m trying to change my approach in writing javascript as I did with PHP.

  • 0

I’m trying to change my approach in writing javascript as I did with PHP. Here is the old code that I check it’s working.

$(document).ready(function(){

    var calculatetotalwidth = $('#container').width()
    var calculatesegment = calculatetotalwidth / 5
    var calculaterating = calculatesegment * rating

    $('#ratings .ratingbar').animate({width:calculaterating},1200);
});

It’s simply a animation that will mimic a progressbar that will display my rating, by segmenting the width of the content div and divide it by the scope I choose (which is 5/5 in this case).

Here is my OOP approach on the problem.

var RatingsBar = {

    fadeOptions: {
    slow: 5000,
    medium: 2500,
    fast: 1200
    },

    Calculate: function (contaierid, score, scope) {

    $(document).ready(function () {

        var calculatetotalwidth = $(contaierid).width()
        var calculatesegment = calculatetotalwidth / scope
        var calculaterating = calculatesegment * score

        $('#ratings .ratingbar').animate({
        width: calculaterating
        }, RatingsBar.fadeOptions.slow);

    });

    } 
}

RatingsBar.Calculate('#container', ratings, 5)

I used the source code pattern in jqueryslideslidemenu plugin. I can’t seem to make it work. Am I missing something here?

I got the thing to work. The problem now, is that I need ratings to be used. I took it from a PHP code here:

    class rating_system {

    var $score;

    function __construct($rate) {
        $this->score = $rate;
    }

    function run_rate() {
        $this->phptojava();
        echo $this->displayrate();
    }


    function phptojava() {
        echo '<script language="javascript" type="text/javascript"> var ratings ='. $this->score ."</script>";
    }

    function displayrate() {
        $wrapper = '<div id="ratings"><div class="ratingbar">';
        $wrapper = $wrapper . '<p>' . $this->score . '<p>';
        $wrapper = $wrapper . '</div>' . '<div class="blankrating">' . '<p>' . 'ratings' . '<p>';
        $wrapper = $wrapper . '</div></div>';

        return $wrapper;
    }

}

$view = new rating_system(4);

Thanks everyone. I manage to get it working.

<html>
<head>

<?php

    class rating_system {

        var $score;

        function __construct($rate) {
            $this->score = $rate;
        }

        function run_rate() {
            $this->phptojava();
            echo $this->displayrate();
        }


        function phptojava() {
            echo '<script language="javascript" type="text/javascript"> var ratings ='. $this->score ."</script>";
        }

        function displayrate() {
            $wrapper = '<div id="ratings"><div class="ratingbar">';
            $wrapper = $wrapper . '<p>' . $this->score . '<p>';
            $wrapper = $wrapper . '</div>' . '<div class="blankrating">' . '<p>' . 'ratings' . '<p>';
            $wrapper = $wrapper . '</div></div>';

            return $wrapper;
        }

    }

    $view = new rating_system(2);
?>

<script type="text/javascript" src="jquery.js" ></script>
<script language="javascript" type="text/javascript">

var RatingsBar = {
    fadeOptions: {slow:5000,medium:2500,fast:1200},
    calculate: function (contaierid, score, scope) {
//      $(document).ready(function() {
                var calculatetotalwidth = $(contaierid).width();
                var calculatesegment = calculatetotalwidth / scope;
                var calculaterating = calculatesegment * score;
                $('#ratings .ratingbar').animate({width:calculaterating}, RatingsBar.fadeOptions.fast);
//          });//end ready function
    }//End Calculate Function
} //end object

$(document).ready(function() { 
    RatingsBar.calculate('#container',ratings,5);

});

</script>

<style type="text/css">

#container {
    height:500px;
    width:720px;

}

#ratings {
    width:720px;
    height:75px;
    position:relative;

    float:left;
}

#ratings .ratingbar {
    width:0px;
    border: 1px #910000 solid;
    height: 100%;
    float:left;
    text-align:right;
    background-image: linear-gradient(bottom, #A62E10 47%, #F52D00 82%);
    background-image: -o-linear-gradient(bottom, #A62E10 47%, #F52D00 82%);
    background-image: -moz-linear-gradient(bottom, #A62E10 47%, #F52D00 82%);
    background-image: -webkit-linear-gradient(bottom, #A62E10 47%, #F52D00 82%);
    background-image: -ms-linear-gradient(bottom, #A62E10 47%, #F52D00 82%);

    background-image: -webkit-gradient(
        linear,
        left bottom,
        left top,
        color-stop(0.47, #A62E10),
        color-stop(0.82, #F52D00)
    );

    filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#A62E10', endColorstr='#F52D00');
}

#ratings .blankrating {
    text-align:left;
}

</style>

</head>

<body>

<div id="container">

<?php echo $view->run_rate(); ?>

</div>
</body>
</html>

This one is the entire code I’m trying.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:37:09+00:00Added an answer on May 26, 2026 at 9:37 pm

    Maybe this would work, hard to tell without a working test case.

    var RatingsBar = {
    
        fadeOptions: {
        slow: 5000,
        medium: 2500,
        fast: 1200
        },
    
        Calculate: function (contaierid, score, scope) {
            var calculatetotalwidth = $(contaierid).width();
            var calculatesegment = calculatetotalwidth / scope;
            var calculaterating = calculatesegment * score;
    
            $('#ratings .ratingbar').animate({
            width: calculaterating
            }, RatingsBar.fadeOptions.slow);
        } 
    };
    
    $(document).ready(function () {
        RatingsBar.Calculate('#container', Ratings, 5);
    });
    

    Try reproducing your problem on jsfiddle.net and post the link.

    Edit : What is Ratings supposed to be (second argument in your function call)? Replace Ratings by any value or define a Ratings variable and the code above works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.