mercredi 25 février 2015

I don't understand how this script works

Hello I have a script that allows checkboxes (Found it online, I didn't program it at all, as I wouldn't even know how to do it..) so you can add multiple products, it works fine and dandy on all other browsers except for internet explorer (Of course..). Could anyone take a look and try to convert it to work with internet explorer and help me to understand how it works as well? Thank you, here is the script:



<script type="text/javascript">
<!--
function Dollar(val) { // force to valid dollar amount
var str, pos, rnd = 0;
if (val < .995) rnd = 1; // for old Netscape browsers
str = escape(val * 1.0 + 0.005001 + rnd); // float, round, escape
pos = str.indexOf(".");
if (pos > 0) str = str.substring(rnd, pos + 3);
return str;
}

function ReadForm(obj1, tst) { // process radio and checkbox
var i, j, amt = 0, des = "", obj, pos, val, tok, tag,
op1a = "", op1b = "", op2a = "", op2b = "", itmn = "";
var ary = new Array();
if (obj1.baseamt) amt = obj1.baseamt.value * 1.0; // base amount
if (obj1.basedes) des = obj1.basedes.value; // base description
if (obj1.baseon0) op1a = obj1.baseon0.value; // base options
if (obj1.baseos0) op1b = obj1.baseos0.value;
if (obj1.baseon1) op2a = obj1.baseon1.value;
if (obj1.baseos1) op2b = obj1.baseos1.value;
if (obj1.baseitn) itmn = obj1.baseitn.value;
for (i = 0; i < obj1.length; i++) { // run entire form
obj = obj1.elements[i]; // a form element
if (obj.type == "checkbox" || obj.type == "radio") { // checkboxes and radios
if (obj.checked) { // did user check it?
val = obj.value; // the value of the selection
ary = val.split(" "); // break apart
for (j = 0; j < ary.length; j++) { // look at all items
// first we do single character tokens...
if (ary[j].length < 2) continue;
tok = ary[j].substring(0, 1); // first character
val = ary[j].substring(1); // get data
if (tok == "@") amt = val * 1.0;
if (tok == "+") amt = amt + val * 1.0;
if (tok == "%") amt = amt + (amt * val / 100.0);
if (tok == "#") { // record item number
if (obj1.item_number) obj1.item_number.value = val;
ary[j] = ""; // zap this array element
}
// Now we do 3-character tokens...
if (ary[j].length < 4) continue;
tok = ary[j].substring(0, 3); // first 3 chars
val = ary[j].substring(3); // get data
if (tok == "s1=") { // value for shipping
if (obj1.shipping) obj1.shipping.value = val;
ary[j] = ""; // clear it out
}
if (tok == "s2=") { // value for shipping2
if (obj1.shipping2) obj1.shipping2.value = val;
ary[j] = ""; // clear it out
}
}
val = ary.join(" "); // rebuild val with what's left

tag = obj.name.substring(obj.name.length - 2); // get flag
if (tag == "1a") op1a = op1a + " " + val;
else if (tag == "1b") op1b = op1b + " " + val;
else if (tag == "2a") op2a = op2a + " " + val;
else if (tag == "2b") op2b = op2b + " " + val;
else if (tag == "3i") itmn = itmn + " " + val;
else if (des.length == 0) des = val;
else des = des + ", " + val;
}
}
else if (obj.name == 'basedes' && obj.selectedIndex != 0){ //calculate when pizza selected, but dont calculate if nothing selected yet
var select_list_selected_index = obj.selectedIndex;
// get text of select list. not value because your show/hide code depends on it and we cant change it
var text = obj.options[select_list_selected_index].text;

ary = text.split("$"); //split at $ sign
val = ary[1]; // get the second item = the amount
amt = amt + eval(val);
}
}
// Now summarize stuff we just processed, above
if (op1a.length > 0) obj1.on0.value = op1a;
if (op1b.length > 0) obj1.os0.value = op1b;
if (op2a.length > 0) obj1.on1.value = op2a;
if (op2b.length > 0) obj1.os1.value = op2b;
if (itmn.length > 0) obj1.item_number.value = itmn;
obj1.item_name.value = des;
obj1.amount.value = Dollar(amt);
if (obj1.tot) obj1.tot.value = "$" + Dollar(amt);
}
//-->
</script>
<script src="FormManager.js">
/****************************************************
* Form Dependency Manager- By Twey- http://www.twey.co.uk
* Visit Dynamic Drive for this script and more: http://ift.tt/L2SPkf
****************************************************/
</script>
<script type="text/javascript">
window.onload = function() {
setupDependencies('weboptions'); //name of form(s). Seperate each with a comma (ie: 'weboptions', 'myotherform' )
};
</script>

<form action="http://ift.tt/rDmnwQ" method="post" onsubmit="this.target='_blank'; return ReadForm(this, true);"
name="weboptions">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="randomemail@hotmail.com" />
<input type="hidden" name="shipping" value="0.00" />
<input type="hidden" name="no_shipping" value="1" />
<input type="hidden" name="return" value="http://ift.tt/1DrmJbo" />
<input type="hidden" name="item_name" />
<input type="hidden" name="amount" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="lc" value="US" />
<input type="hidden" name="bn" value="PP-ShopCartBF" />
&nbsp;<strong><font face="Arial" size="5">Add transmission:</font></strong>
<div class="test" style="height: 50%; margin: 0px auto;">
<ul>
<li>
<label><input class="Transmission" type="checkbox" onclick="ReadForm (this.form, false);"
name="68RFE Transmission" value="68RFE +9500" />Standard 68RFE Transmission - $9,500</label>
</li>
</ul>
</div>
<p>
&nbsp;</p>
<div class="test" style="height: 50%; margin: 0px auto;">
<p>
<strong><font face="Arial" size="5">Upgrades:</font></strong></p>
<p>
<center>
<ul>
<li><label>
<input class="Frictions" type="checkbox" onclick="ReadForm (this.form, false);"
name="Ultra Performance Frictions" value="UPF +20.50" />Ultra Performance Frictions, add: $20.50</label>
</li>
<li><label>
<input class="Steels" type="checkbox" onclick="ReadForm (this.form, false);"
name="Kolene Steels" value="KS +1.25" />Kolene Steels, add: $1.25</label>
</li>
<li><label>
<input class="Billet input-shaft" type="checkbox" onclick="ReadForm (this.form, false);"
name="Billet input-shaft with forward drum" value="Bill i-s +1.25" />Billet input-shaft with forward drum, add: $1.25</label>
</li>
<li><label>
<input class="HD clutch spring" type="checkbox" onclick="ReadForm (this.form, false);"
name="Heavy duty over drive direct clutch spring" value="OD CS +1.45" />Heavy duty over drive direct clutch spring, add: $1.45</label>
</li>
<li><label>
<input class="HD front band strut" type="checkbox" onclick="ReadForm (this.form, false);"
name="Heavy duty front band strut" value="FBS +3.55" />Heavy duty front band strut, add: $3.55</label>
</li>
<li><label>
<input class="Super servo" type="checkbox" onclick="ReadForm (this.form, false);"
name="Super servo (Rear)" value="SS +3.55" />Super servo (Rear), add: $3.55</label>
</li>
<li><label>
<input class="High cap alum pan" type="checkbox" onclick="ReadForm (this.form, false);"
name="High capacity deep aluminum pan" value="HCDP +3.55" />High capacity deep aluminum pan, add: $3.55</label>
</li>
<li><label>
<input class="Trip Disk Bill" type="checkbox" onclick="ReadForm (this.form, false);"
name="Triple disk billet lid low stall torque converter" value="TD billet +3.55" />Triple disk billet lid low stall torque converter, add: $3.55</label>
</li>

<small><span title="Why do I need upgrades?!"><a href="upgrades.html">Why are these upgrades important?</a></span></small>
<p><strong> Total: <input class="nbor" size="7" name="tot" type="text" /></strong></p>
<p><input type="submit" name="B1" value="Add to cart" /></p>
</ul>




Aucun commentaire:

Enregistrer un commentaire