darkus
05-14-2009, 01:31 AM
I've spend about 2 days writing this javascript code and it works great in IE only to find out that it does nothing in Safari/FF. After smashing my head into a wall for a few hours I decided to ask for some help
Here is my code:
<script type="text/javascript">function calculate() {
var thetotal = 0;
var silver = 0;
var gold = 0;
var banners = 0;
var pname01 = document.getElementById("pname01").value;
if (pname01 == "Silver") { silver = silver + 1;}
if (pname01 == "Gold") { gold = gold + 1;}
}
var ptime = document.getElementById("ptime").value;
if (ptime == 3) { mos = 1; }
if (ptime == 4) { mos = 3; }
if (ptime == 5) { mos = 6; }
if (ptime == 6) { mos = 12; }
if (silver > 0) { silverinit = 1; } else { silverinit = 0; }
if (gold > 0) { goldinit = 1; } else { goldinit = 0; }
silverupgrade = silver - 1;
goldupgrade = gold - 1;
if (gold > 1) { golddiscount = (gold - 1) * 12 } else { golddiscount = 0; }
if (silverupgrade < 0) { silverupgrade = 0; }
if (goldupgrade < 0) { goldupgrade = 0; }
if ((silverinit == 1) && (goldinit == 1)) { silverinit = 0; silverupgrade = silverupgrade + 1; }
thetotal = ((silverinit * 18) + (silverupgrade * 8)) + ((goldinit * 32) + (goldupgrade * 18) - golddiscount);
thetotal = thetotal * mos;
thetotal = "$" + thetotal;
document.getElementById("thetotal").value = thetotal;
}</script>
<form>
.... a bunch of form elements
<button type="button" value="button" onclick="calculate();" style="background-color: yellow; border:1px solid #aaa;">Calculate</button>
Total: <input type="text" id="thetotal" onfocus="this.blur();" />
</form>
Basicly what the script does is using some variables in my form will calculate a total price in real time when you click the "Calculate" button. Works great in IE, but in Firefox/Safari it won't do a thing..
thanks for any help!
Here is my code:
<script type="text/javascript">function calculate() {
var thetotal = 0;
var silver = 0;
var gold = 0;
var banners = 0;
var pname01 = document.getElementById("pname01").value;
if (pname01 == "Silver") { silver = silver + 1;}
if (pname01 == "Gold") { gold = gold + 1;}
}
var ptime = document.getElementById("ptime").value;
if (ptime == 3) { mos = 1; }
if (ptime == 4) { mos = 3; }
if (ptime == 5) { mos = 6; }
if (ptime == 6) { mos = 12; }
if (silver > 0) { silverinit = 1; } else { silverinit = 0; }
if (gold > 0) { goldinit = 1; } else { goldinit = 0; }
silverupgrade = silver - 1;
goldupgrade = gold - 1;
if (gold > 1) { golddiscount = (gold - 1) * 12 } else { golddiscount = 0; }
if (silverupgrade < 0) { silverupgrade = 0; }
if (goldupgrade < 0) { goldupgrade = 0; }
if ((silverinit == 1) && (goldinit == 1)) { silverinit = 0; silverupgrade = silverupgrade + 1; }
thetotal = ((silverinit * 18) + (silverupgrade * 8)) + ((goldinit * 32) + (goldupgrade * 18) - golddiscount);
thetotal = thetotal * mos;
thetotal = "$" + thetotal;
document.getElementById("thetotal").value = thetotal;
}</script>
<form>
.... a bunch of form elements
<button type="button" value="button" onclick="calculate();" style="background-color: yellow; border:1px solid #aaa;">Calculate</button>
Total: <input type="text" id="thetotal" onfocus="this.blur();" />
</form>
Basicly what the script does is using some variables in my form will calculate a total price in real time when you click the "Calculate" button. Works great in IE, but in Firefox/Safari it won't do a thing..
thanks for any help!