...

View Full Version : Problems with Javascript on Wordpress.org site. Is there a way to convert?



nicknick43
01-25-2010, 05:12 PM
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?


<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>

JAY6390
01-25-2010, 07:07 PM
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

nicknick43
01-25-2010, 07:35 PM
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.

JAY6390
01-25-2010, 07:37 PM
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

nicknick43
01-25-2010, 07:49 PM
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.

JAY6390
01-25-2010, 07:51 PM
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

nicknick43
01-25-2010, 08:34 PM
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.

JAY6390
01-26-2010, 02:14 AM
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 :confused:

To get the code into your page I would use the following

<?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)

nicknick43
01-26-2010, 05:36 AM
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.

nicknick43
01-26-2010, 05:27 PM
Jay, nevermind I think I found the /js path to load the .js file. I will try to apply your code tonight.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum