WordPress.org

Ready to get started?Download WordPress

Forums

[closed] Problem calling on JS function in page (3 posts)

  1. Cwackerfuss
    Member
    Posted 1 year ago #

    Here's my JS file that has been loaded into Header.php:

    // NUMBER TO IMAGE CONVERSION
    function counterimages(input) {
        var output = ""
    
        for (var i = 0; i < input.length; i++) {
            var chr = input.substring(i, i + 1)
            if (chr == '£') {
                output += '<img border="0" src="img/pound.gif">';
            } else if (chr == '.') {
                output += '<img border="0" src="img/dot.gif">';
            } else {
                output += '<img border="0" src="http://eatiply3.staging.wpengine.com/wp-content/uploads/2013/05/'+(chr+1)+'.png">';
            }
        return output;
    }
    // NUMBER COUNTER
    var START_DATE = new Date("October 21, 2012 22:30:00"); // put in the starting date here
    var INTERVAL = 1; // refresh interval in seconds
    var INCREMENT = 769.2;  // increase per tick (1/0.0013 ~ 769)
    var START_VALUE = 35000; // initial value when it's the start date
    var count = 0;
    
    jQuery(document).ready(function($) {
     var msInterval = INTERVAL * 1000;
     var now = new Date();
     count = parseInt((now - START_DATE)/msInterval) * INCREMENT + START_VALUE;
     $('#counter').html(count.toFixed(0));
    
     window.setInterval( function(){
        count += INCREMENT;
        $('#counter').html(count.toFixed(0));
     }, msInterval);
    
    });

    What it should do is show a number count-up at the given increment and interval, but substitute the numbers 0-9 for images named respectively.
    I am able to make the second script work by plugging in <div id="counter"></div>Meals Provided into the WordPress page, but for the life of me I can't get the numbers to convert to images. Here's what I thought would work: `<script type="text/javascript" src="/js/counter.js"></script>
    <script type="text/javascript">
    <!--
    counterimages(input);
    //--></script>
    <div id="counter"></div>Meals Provided`

    Thanks!

  2. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    A function should be added to functions.php and called in your header.php (or where needed).

    <?php counterimages();?>

    Test per:

    http://wordpress.stackexchange.com/questions/91434/calling-a-function-from-functions-php-in-header

  3. Andrew
    Forum Moderator
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Topic