0

Hello i want to use counter which takes value from js file, but i want to change it.

Here is js code;

function countUp(count)
 {
var div_by = 100,
    speed = Math.round(count / div_by),
    $display = $('.count'),
    run_count = 1,
    int_speed = 24;

var int = setInterval(function() {
    if(run_count < div_by){
        $display.text(speed * run_count);
        run_count++;
    } else if(parseInt($display.text()) < count) {
        var curr_count = parseInt($display.text()) + 1;
        $display.text(curr_count);
    } else {
        clearInterval(int);
    }
}, int_speed);
 }

  countUp(600);

It counts to 600 but i want assign variable to this from database probly with codebehind.

Here is html code ;

        <div class="col-lg-3 col-sm-6">
                  <section class="panel">
                      <div class="symbol red">
                        <i class=" fa fa-times text-muted"></i>
                      </div>
                      <div class="value">
                          <h1 class="count">123123123</h1>
                          <p>Position Canceled</p>
                      </div>
                  </section>
              </div>

How can i change countUp value in js. Please help me. Thank You

2 Answers 2

1
function countUp(count)
 {
var div_by = 100,
    speed = Math.round(count / div_by),
    $display = $('.count'),
    run_count = 1,
    int_speed = 24;

var int = setInterval(function() {
    if(run_count < div_by){
        $display.text(speed * run_count);
        run_count++;
    } else if(parseInt($display.text()) < count) {
        var curr_count = parseInt($display.text()) + 1;
        $display.text(curr_count);
    } else {
        clearInterval(int);
    }
}, int_speed);
 }



var _count=0;

//If you are retreiving count from database, you can perform ajax call

var request = $.ajax({
            url: url,
            type: "GET",            
            dataType: json
        });

        request.done(function(msg) {
            _count=msg.data;            
        });

        request.fail(function(jqXHR, textStatus) {
            alert( "Request failed: " + textStatus );
        });

//if you are assinging count value from html tags eg: assign value into hidden field, then

<input type="hidden" id="count" value="600"/>
_count=$('#count).val();
  countUp(600);
Sign up to request clarification or add additional context in comments.

Comments

0

You can use following syntax:

countUp('<%= CountValueFromDB %>');

Where CountValueFromDB is variable you can declare in your code-behind for particular page and populate it from database or any other source in your Page_Load method or another method called during page life cycle.

Alternatively you can call RegisterStartupScript in your code behind passing "countUp(" + CountValueFromDB + ");" for 'script' parameter.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.