Title: Trouble Creating Javascript Tool in WordPress Page
Last modified: August 31, 2016

---

# Trouble Creating Javascript Tool in WordPress Page

 *  [meggo4all](https://wordpress.org/support/users/meggo4all/)
 * (@meggo4all)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/trouble-creating-javascript-tool-in-wordpress-page/)
 * Hoping I can get some help – I don’t know much (or anything) about code, but 
   I am trying to create a name generator tool for my website.
 * I found a free piece of code that allowed me to download a name generator javascript
   code and then cut and pasted names I wanted to generate. I saved the code as 
   a name-generator.js and uploaded it to the root domain of my website.
 * I read in the Using Javascript codex that when you want to use javascript on 
   one specific page/post, you put this in:
 *     ```
       <script type="text/javascript" src="/scripts/updatepage.js"></script>
       <script type="text/javascript">
       <!--
       updatepage();
       //--></script>
       ```
   
 * I did this in my post, replacing “updatepage.js” with “name-generator.js” but
   nothing shows up.
 * I also do not understand when the codex says
 *     ```
       Make sure that each script is defined by its function name, such as:
   
       function updatepage(){var m="Page updated "+document.lastMo.......}
       ```
   
 * The function used in my javascript is:
    function generator() so I replaced the“
   updatepage()” with “generator()” but I do not know if that makes sense.
 * I put the name-generator.js file in a scripts directory folder that I created.
 * Here is the page where I posted the generator:
    [http://www.k9ofmine.com/dog-name-generator-test](http://www.k9ofmine.com/dog-name-generator-test)
 * Here is a link to the script I created (using a template):
    [http://www.k9ofmine.com/scripts/name-generator.js](http://www.k9ofmine.com/scripts/name-generator.js)
 * As you can see, currently clicking the “make name” button results in no action
   or result.
 * Any help you can offer would be greatly appreciated! As I said, I know very little
   about code but am hoping to get this name generator working.
 * Thanks so much!

Viewing 1 replies (of 1 total)

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 4 months ago](https://wordpress.org/support/topic/trouble-creating-javascript-tool-in-wordpress-page/#post-7145167)
 * The right way to do this is to enqueue your JavaScript file through a Child Theme.
 * First step: Set up a Child Theme: [https://codex.wordpress.org/Child_Themes](https://codex.wordpress.org/Child_Themes)
 * Then look at the ‘wp_enqueue_script’ function that you’re going to use to load
   this JavaScript file: [https://developer.wordpress.org/reference/functions/wp_enqueue_script/](https://developer.wordpress.org/reference/functions/wp_enqueue_script/)
 * I would recommend enquing 2 .js files, one for the library (updatepage.js) and
   then one for your JavaScript initiations (`updatepage();`).

Viewing 1 replies (of 1 total)

The topic ‘Trouble Creating Javascript Tool in WordPress Page’ is closed to new 
replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/trouble-creating-javascript-tool-in-wordpress-page/#post-7145167)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
