Title: Problems Using JavaScript on a Page
Last modified: August 21, 2016

---

# Problems Using JavaScript on a Page

 *  [Cwackerfuss](https://wordpress.org/support/users/cwackerfuss/)
 * (@cwackerfuss)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/problems-using-javascript-on-a-page/)
 * Hello All,
    I’m trying to plug some JavaScript into a page to display a Counter
   using this code: [http://jsfiddle.net/nQjPE/](http://jsfiddle.net/nQjPE/), but
   for the life of me I can’t figure out how to make it work.
 * I’d also like to use a JS script to turn each number (0, 1, 2, etc. up to 9) 
   into an image representation of the number. I’m thinking something like this 
   will work, but again, I don’t know how to apply it to my page. [http://bytes.com/topic/javascript/answers/169321-how-display-numbers-images-nuff-easy](http://bytes.com/topic/javascript/answers/169321-how-display-numbers-images-nuff-easy)
 * Any help would be greatly appreciated.
    Thanks! Chase

Viewing 11 replies - 1 through 11 (of 11 total)

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [13 years, 1 month ago](https://wordpress.org/support/topic/problems-using-javascript-on-a-page/#post-3729614)
 * See this article on using JavaScript in WordPress [http://codex.wordpress.org/Using_Javascript](http://codex.wordpress.org/Using_Javascript)
 * noConflict wrappers would look like this [http://jsfiddle.net/nQjPE/12/](http://jsfiddle.net/nQjPE/12/)
 *  Thread Starter [Cwackerfuss](https://wordpress.org/support/users/cwackerfuss/)
 * (@cwackerfuss)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/problems-using-javascript-on-a-page/#post-3729627)
 * So this is what the code should look like in WordPress?
 *     ```
       <html>
       <head>
       <title>JavaScript Replace</title>
   
       <script language="JavaScript1.1" type="text/javascript">
       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,10) * INCREMENT + START_VALUE;
        $('#counter').html(count.toFixed(0));
   
        window.setInterval( function(){
           count += INCREMENT;
           $('#counter').html(count.toFixed(0));
        }, msInterval);
   
       });
       </script>
       </head>
       <body>
   
       <div id="counter"></div> Network Users
   
       </body>
       </html>
       ```
   
 * _[Please post code & markup between backticks or use the code button. Your posted
   code may now have been permanently damaged by the forum’s parser.]_
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [13 years, 1 month ago](https://wordpress.org/support/topic/problems-using-javascript-on-a-page/#post-3729635)
 * Try enqueuing it instead [http://codex.wordpress.org/Function_Reference/wp_enqueue_script](http://codex.wordpress.org/Function_Reference/wp_enqueue_script)
 *  Thread Starter [Cwackerfuss](https://wordpress.org/support/users/cwackerfuss/)
 * (@cwackerfuss)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/problems-using-javascript-on-a-page/#post-3729839)
 * Hey Andrew Nevins,
 * I’ve been reading more about enqueue-ing and just have a few questions as to 
   the process.
 * I first put my JS file in the js folder.
    Then I add this code to the Functions.
   php folder: function meal_counter_js () { wp_enqueue_script(‘meal_counter’, get_template_directory_uri().‘
   js/counter.js’, array(‘jquery’), ‘1.0’, false); } // End meal_counter_js()
 * Then how do I call upon the code on a specific page?
 * Thank you for all your help!
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/problems-using-javascript-on-a-page/#post-3729840)
 * If you have enqueued the script correctly (and it sounds like you have), it will
   now be available on all pages on your WordPress site.
 *  Thread Starter [Cwackerfuss](https://wordpress.org/support/users/cwackerfuss/)
 * (@cwackerfuss)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/problems-using-javascript-on-a-page/#post-3729841)
 * Thanks for the speedy response,
    Do I use add_action(‘wp_print_scripts’, ‘meal_counter_js’,
   1); within the page’s content to call on the script?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/problems-using-javascript-on-a-page/#post-3729842)
 * Do you want the script on all pages of your site? Or just a specific page?
 *  Thread Starter [Cwackerfuss](https://wordpress.org/support/users/cwackerfuss/)
 * (@cwackerfuss)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/problems-using-javascript-on-a-page/#post-3729843)
 * Just a specific page.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/problems-using-javascript-on-a-page/#post-3729845)
 * Is this a static Page or a Post?
 *  Thread Starter [Cwackerfuss](https://wordpress.org/support/users/cwackerfuss/)
 * (@cwackerfuss)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/problems-using-javascript-on-a-page/#post-3729846)
 * A static page
 *  Thread Starter [Cwackerfuss](https://wordpress.org/support/users/cwackerfuss/)
 * (@cwackerfuss)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/problems-using-javascript-on-a-page/#post-3729852)
 * Esmi! Andrew! I got it to work!!
 * I simply added `<div id="counter"></div> Network Users` inside the page. Perfect!
   Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Problems Using JavaScript on a Page’ is closed to new replies.

## Tags

 * [image](https://wordpress.org/support/topic-tag/image/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 11 replies
 * 3 participants
 * Last reply from: [Cwackerfuss](https://wordpress.org/support/users/cwackerfuss/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/problems-using-javascript-on-a-page/#post-3729852)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
