Wordpress and Javascript in a Post?? Help

Discussion in 'WordPress' started by wallarookiller, Jan 5, 2009.

  1. #1
    I'm trying to put some simple javascript calculators in a post on my wordpress run blog. I host it myself and can't figure out how to do it. I've looked at a few plugins but I'd rather do it by hand.

    If you go to http://codex.wordpress.org/Using_Javascript#Javascript_in_Posts it tells you how but I don't quite understand. I know how to call stuff to an extant but I'm a little confused. If any one could give me just a working example that would be absolutely great.

    Thanks guys and I hope someone can help.....
     
    wallarookiller, Jan 5, 2009 IP
  2. sadcox

    sadcox Peon

    Messages:
    162
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    One thing you need to do is make sure you are using the html editor instead of the visual editor (It's a tab on the editor). From there it should just be copy and paste if the js is correct.
     
    sadcox, Jan 5, 2009 IP
  3. bojomojo

    bojomojo Peon

    Messages:
    921
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I checked the link you provided, it simply means but your JS code into a .js file and upload it to your server, then call it from within the post, after than use the functions you need, as an alternative to putting it into the header
     
    bojomojo, Jan 5, 2009 IP
  4. wallarookiller

    wallarookiller Active Member

    Messages:
    647
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #4
    It doesn't work that way Wordpress strips out javascript even when you use the html editor.

    Thats the part that confuses me. I can create the javascript file no problem and upload it but how do I call it? I tried but to no avail. Any chance someone could show me an example?
     
    wallarookiller, Jan 5, 2009 IP
  5. bojomojo

    bojomojo Peon

    Messages:
    921
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #5
    First off go to USERS ----> TEXT EDITOR and turn off the RICH EDITOR

    then go to your post, add:
    
    <script type="text/javascript" src="/scripts/updatepage.js"></script>  // this should load your js file
    <script type="text/javascript">
    <!--
    updatepage();                 // this here is just an example of the functions you have defined in the js file
    //--></script>
    
    Code (markup):
     
    bojomojo, Jan 5, 2009 IP