Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Problems with Javascript on Wordpress.org site. Is there a way to convert?

    Bare with me as I am a step below rookie when it comes to code and or script. I have a website that is a wordpress.org site. I have, with a TON of help from the guys in the javascript category on this forum, created a code for a pricing page on my site. However I think there are still issues with javascript and wordpress and it will display correctly but the function does not work in the end. I have tested the following code and it works perfectly just NOT on my site. Is there a way to convert this code to something that is more wordpress friendly?

    Code:
    <html>
    <head>
    <script type="text/javascript">
    // <![CDATA[
    function addemup(form)
    {
        var total = 0;
        var count = 0;
        var html = "";
        for (var phase = 1; phase <= 5; ++phase )
        {
            var phtotal = 0;
            var cbs = form.elements["Phase " + phase];
    // alert(phase + "\n" + cbs.length);
            if ( cbs.length == null )
            {
                if ( cbs.checked ) phtotal += parseInt(cbs.value,10);
            } else {
    // alert(phase + "XX\n" + cbs.length);
                for (var i=0; i < cbs.length; i++)      
                {       
                    if ( cbs[i].checked) phtotal += parseInt(cbs[i].value, 10);
                }
            }
            html += "Total for Phase " + phase + " is " + phtotal + "<br/>";
            total += phtotal;
        }  
        html += "<br/>Overall total, all phases, is " + total;
        var div = document.getElementById("totals");
        div.innerHTML = html;
        div.style.display = "block";
    
    }
    // ]]>
    </script>
    </head>
    <body>
    <form>
    <div class="item">
    <h4>Phase 1: Structurals</h4>
    </div>
    <input name="Phase 1" type="checkbox" value="0" /> Phase 1: Complete w/ Engineering
    
    <input name="Phase 1" type="checkbox" value="0" /> Phase 1: Complete w/ Out Engineering
    
    <input name="Phase 1" type="checkbox" value="10" /> Foundation: Monoslab
    
    <input name="Phase 1" type="checkbox" value="20" /> Foundation: Post Tension
    
    <input name="Phase 1" type="checkbox" value="30" /> Foundation: Stemwall
    
    <input name="Phase 1" type="checkbox" value="40" /> Foundation: Basement
    
    <input name="Phase 1" type="checkbox" value="40" /> Framing w/ Engineering
    
    <input name="Phase 1" type="checkbox" value="40" /> Framing w/ out Engineering
    
    <input name="Phase 1" type="checkbox" value="40" /> Framing Hardware (with Engineering ONLY)
    <div class="item">
    <h4>Phase 2: Mechanicals</h4>
    </div>
    <input name="Phase 2" type="checkbox" value="0" /> Phase 2: Complete w/ Engineering
    
    <input name="Phase 2" type="checkbox" value="0" /> Phase 2: Complete w/ Out Engineering
    
    <input name="Phase 2" type="checkbox" value="10" /> Plumbing
    
    <input name="Phase 2" type="checkbox" value="20" /> HVAC
    
    <input name="Phase 2" type="checkbox" value="30" /> Electrical
    <div class="item">
    <h4>Phase 3: Exterior Finishes</h4>
    </div>
    <input name="Phase 3" type="checkbox" value="0" /> Phase 3: Complete
    
    <input name="Phase 3" type="checkbox" value="0" /> Housewrap
    
    <input name="Phase 3" type="checkbox" value="10" /> Brick
    
    <input name="Phase 3" type="checkbox" value="20" /> Stone
    
    <input name="Phase 3" type="checkbox" value="30" /> Vinyl Siding
    
    <input name="Phase 3" type="checkbox" value="30" /> Cementitious Siding
    
    <input name="Phase 3" type="checkbox" value="30" /> Roofing
    
    <input name="Phase 3" type="checkbox" value="30" /> Windows
    
    <input name="Phase 3" type="checkbox" value="30" /> Exterior Doors
    <div class="item">
    <h4>Phase 4: Interior Finishes</h4>
    </div>
    <input name="Phase 4" type="checkbox" value="0" /> Phase 4: Complete
    
    <input name="Phase 4" type="checkbox" value="0" /> Insulation
    
    <input name="Phase 4" type="checkbox" value="10" /> Drywall
    
    <input name="Phase 4" type="checkbox" value="20" /> Paint
    
    <input name="Phase 4" type="checkbox" value="30" /> Interior Trim
    
    <input name="Phase 4" type="checkbox" value="30" /> Interior Doors
    
    <input name="Phase 4" type="checkbox" value="30" /> Mirrors
    
    <input name="Phase 4" type="checkbox" value="20" /> Shelving
    
    <input name="Phase 4" type="checkbox" value="30" /> Bath Accessories
    
    <input name="Phase 4" type="checkbox" value="30" /> Countertops
    
    <input name="Phase 4" type="checkbox" value="30" /> Cabinets
    
    <input name="Phase 4" type="checkbox" value="30" /> Shower Surrounds
    
    <input name="Phase 4" type="checkbox" value="30" /> Shower Enclosures
    <div class="item">
    <h4>Phase 5: Flooring</h4>
    </div>
    <input name="Phase 5" type="checkbox" value="0" /> Flooring
    
    <hr>
    <input onclick="addemup(this.form)" type="button" value="Estimated Cost" />
    <div id="totals" style="display: none;">
    </div>
     
    </form>
    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Does the wordpress.org site even allow you to have your own javascript code running on their site? I thought it was all wrapped up kinda tight unless you pay for the advanced themes etc
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    New Coder
    Join Date
    Jan 2010
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Wordpress.org (paid) sites (like mine) allow javascript and access to .php files and .css info. A wordpress.com (free) site does not allow either from what I understand.

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    So the paid versions all have the .org extension? I thought the .org site was for downloading the free copy of it for use on your own server
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #5
    New Coder
    Join Date
    Jan 2010
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Yes that it what it's for. I guess I consider this the "paid" version because you have to then host it yourself or pay for hosting like I did.

  • #6
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Oh OK, the paid thing threw me, and I'm sure it would others since it's the opensource version. Do you have a link to the site so that it can be viewed and possibly work out the problem
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #7
    New Coder
    Join Date
    Jan 2010
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Yeah here it is:

    http://residentialestimators.com/?page_id=64

    The page is password protected. Use password resest2010 to view the page.

    Thanks a bunch.

  • #8
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Sorry only just been able to take a look at this. I can't see the addemup function you have above anywhere in the source

    To get the code into your page I would use the following
    PHP Code:
    <?php if_single('64') { ?><script type="text/javascript" src="/path/to/custom.js"></script><?php ?>
    in your <head> tags in the header.php file for your theme, then create a custom.js wherever you want it and add the javascript to it. That js will only be loaded for that one post (64)
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • Users who have thanked JAY6390 for this post:

    nicknick43 (01-26-2010)

  • #9
    New Coder
    Join Date
    Jan 2010
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thanks for your help Jay, I've been at it for a half an hour and I can't figure out how to get this to work. Which portion of the code I put in do I paste into that? I saved the code to my computer as a .js file, but it will be looking for a path right? How to I get the file into wordpress? Sorry so many questions, it seems like every time I get close I hit a roadblock and all the while I watch the code work in my cheap-o code testing program. So disheartening.

  • #10
    New Coder
    Join Date
    Jan 2010
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Jay, nevermind I think I found the /js path to load the .js file. I will try to apply your code tonight.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •