WordPress.org

Ready to get started?Download WordPress

Forums

how to add javascrpit to a webpage (17 posts)

  1. SCO7TY
    Member
    Posted 1 year ago #

    I've been at this for about 2 hours and had no progress. I know barely anything about javascript but this seems fairly straight forward, probably a matter of putting the code in the correct place.

    I want to put the calculator from this page - http://javascript.about.com/library/blfat2.htm on my page which is here - http://completemuscleandfitness.com/index.php/body-fat-calculator/

    I would really appreciate it if someone could tell me where in my header.php i need to put the following - <script type="text/javascript" src="fatcalc.js"></script>

    I have placed it in a number of places and still havent managed to get this calc to work.

    The actual fatcalc.js is curently placed in - htdocs/wp-content/themes/theme-name/fatcalc.js

    Should it be placed somewhere else?

    Thanks in advance for your help....

  2. SCO7TY
    Member
    Posted 1 year ago #

    This is my Header.php - http://pastebin.com/71Vv3kVQ

  3. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

  4. SCO7TY
    Member
    Posted 1 year ago #

    Read through that over and over, can't grasp it....

    I did research before posting for help on here....

  5. esmi
    Forum Moderator
    Posted 1 year ago #

  6. SCO7TY
    Member
    Posted 1 year ago #

    Thanks but that has baffled me even more!

    I was just hoping to get some direct help rather than links to pages...

    Really struggling with this

  7. esmi
    Forum Moderator
    Posted 1 year ago #

    WordPress is free software and this free, volunteer-staffed forum is the only support resource available via wordpress.org. Here, we help people learn and help themselves rather than do the work for them. That said, if you cannot manage this yourself, perhaps you need to consider hiring someone to carry out the work for you.

  8. SCO7TY
    Member
    Posted 1 year ago #

    I've managed to get actual help on this forum previously rather than links.

    I'm not asking anyone to do the work for me, i asked for 'help'

    I appreciate you providing the links for me, but I've already read through the stuff and haven't managed to get any further afterwards, hence the reason for asking for help here.

    I cant afford to hire someone, again, the reason I'm asking for help here.....

  9. esmi
    Forum Moderator
    Posted 1 year ago #

    All the information you need is on the two Codex pages that we have already posted here.

  10. Phil
    Member
    Posted 1 year ago #

    Place it near this:

    <script type="text/javascript">
            document.documentElement.className = 'js';
    </script>

    ...and I guess you'll want something like this:

    <script type="text/javascript" src="/wp-content/themes/theme-name/fatcalc.js"></script>

    ...although the suggestion above for 'wp_enqueue_script' is the correct way to do it and I'm sure it has advantages as far as avaoiding conflicts between different scripts as well.

    If it's not working then it could be a script conflict, so seriously look at the enqueue method.

    Phil

  11. SCO7TY
    Member
    Posted 1 year ago #

    I find wp_enqueue_script really confusing.

    Is it possible to get this calculator working by using the information from here - http://codex.wordpress.org/Using_Javascript

    I'm trying my best to understand this, just don't want to be wasting my time.

  12. Phil
    Member
    Posted 1 year ago #

    Check your functions.php file as you may find it already enqueues scripts from there anyway, just add the calculator to it.

    Worth a look.

  13. SCO7TY
    Member
    Posted 1 year ago #

    Thanks Phil, appreciate the help. Had no luck with your first suggestion.

    I'll have a look at the functions.php now

  14. SCO7TY
    Member
    Posted 1 year ago #

    Doesnt look like functions.php enqueues scripts.

    Thanks anyway, think it might be time to give up on this one...

  15. Phil
    Member
    Posted 1 year ago #

    Why not get it working on a normal HTML or PHP page, then transfer it over to your WP site.

  16. SCO7TY
    Member
    Posted 1 year ago #

    I seem to be getting somewhere with a PHP page.

    You have been a great help thanks!!

  17. Phil
    Member
    Posted 1 year ago #

    No probs, we all learnt at some point ;)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags