Mercurial > laserkard
view buycode.js @ 17:1481aa25c3c7 laserkard
[svn r18] save
author | rlm |
---|---|
date | Sat, 02 Jan 2010 17:41:29 -0500 |
parents | c96cb4e773e5 |
children | ae22c2d59891 |
line wrap: on
line source
3 function clearDefault(el) {4 if (el.defaultValue==el.value) el.value = ""5 }8 function Dollar (val) { // force to valid dollar amount9 var str,pos,rnd=0;10 if (val < .995) rnd = 1; // for old Netscape browsers11 str = escape (val*1.0 + 0.005001 + rnd); // float, round, escape12 pos = str.indexOf (".");13 if (pos > 0) str = str.substring (rnd, pos + 3);14 return str;15 }17 var amt,des,obj,val,op1a,op1b,op2a,op2b,op3a,op3b,op4a,op4b,op5a,op5b,op6a,op6b,op7a,op7b,op8a,op8b,op9a,op9b,itmn;19 function ChkTok (obj1) {20 var j,tok,ary=new Array (); // where we parse21 ary = val.split (" "); // break apart22 for (j=0; j<ary.length; j++) { // look at all items23 // first we do single character tokens...24 if (ary[j].length < 2) continue;25 tok = ary[j].substring (0,1); // first character26 val = ary[j].substring (1); // get data27 if (tok == "@") amt = val * 1.0;28 if (tok == "+") amt = amt + val*1.0;29 if (tok == "%") amt = amt + (amt * val/100.0);30 if (tok == "-") amt = amt - val*1.0;31 if (tok == "#") { // record item number32 if (obj1.item_number) obj1.item_number.value = val;33 ary[j] = ""; // zap this array element34 }35 // Now we do 3-character tokens...36 if (ary[j].length < 4) continue;37 tok = ary[j].substring (0,3); // first 3 chars38 val = ary[j].substring (3); // get data39 if (tok == "s1=") { // value for shipping40 if (obj1.shipping) obj1.shipping.value = val;41 ary[j] = ""; // clear it out42 }43 if (tok == "s2=") { // value for shipping244 if (obj1.shipping2) obj1.shipping2.value = val;45 ary[j] = ""; // clear it out46 }47 }48 val = ary.join (" "); // rebuild val with what's left49 }51 function StorVal () {52 var tag;53 tag = obj.name.substring (obj.name.length-2); // get flag54 if (tag == "1a") op1a = op1a + " " + val;55 else if (tag == "1b") op1b = op1b + " " + val;56 else if (tag == "2a") op2a = op2a + " " + val;57 else if (tag == "2b") op2b = op2b + " " + val;58 else if (tag == "3a") op3a = op3a + " " + val;59 else if (tag == "3b") op3b = op3b + " " + val;60 else if (tag == "4a") op4a = op4a + " " + val;61 else if (tag == "4b") op4b = op4b + " " + val;62 else if (tag == "5a") op5a = op5a + " " + val;63 else if (tag == "5b") op5b = op5b + " " + val;64 else if (tag == "6a") op6a = op6a + " " + val;65 else if (tag == "6b") op6b = op6b + " " + val;66 else if (tag == "7a") op7a = op7a + " " + val;67 else if (tag == "7b") op7b = op7b + " " + val;68 else if (tag == "8a") op8a = op8a + " " + val;69 else if (tag == "8b") op8b = op8b + " " + val;70 else if (tag == "9a") op9a = op9a + " " + val;71 else if (tag == "9b") op9b = op9b + " " + val;72 else if (tag == "3i") itmn = itmn + " " + val;73 else if (des.length == 0) des = val;74 else des = des + ", " + val;75 }77 function ReadForm (obj1, tst) { // Read the user form78 var i,j,pos;79 amt=0;des="";op1a="";op1b="";op2a="";op2b="";op3a="";op3b="";op4a="";op4b="";op5a="";op5b="";op6a="";op6b="";op7a="";op7b="";op8a="";op8b="";op9a="";op9b="";itmn="";80 if (obj1.baseamt) amt = obj1.baseamt.value*1.0; // base amount81 if (obj1.basedes) des = obj1.basedes.value; // base description82 if (obj1.baseon0) op1a = obj1.baseon0.value; // base options83 if (obj1.baseos0) op1b = obj1.baseos0.value;84 if (obj1.baseon1) op2a = obj1.baseon1.value;85 if (obj1.baseos1) op2b = obj1.baseos1.value;86 if (obj1.baseon2) op3a = obj1.baseon2.value;87 if (obj1.baseos2) op3b = obj1.baseos2.value;88 if (obj1.baseon3) op4a = obj1.baseon3.value;89 if (obj1.baseos3) op4b = obj1.baseos3.value;90 if (obj1.baseon4) op5a = obj1.baseon4.value;91 if (obj1.baseos4) op5b = obj1.baseos4.value;92 if (obj1.baseon5) op6a = obj1.baseon5.value;93 if (obj1.baseos5) op6b = obj1.baseos5.value;94 if (obj1.baseon6) op7a = obj1.baseon6.value;95 if (obj1.baseos6) op7b = obj1.baseos6.value;96 if (obj1.baseon7) op8a = obj1.baseon7.value;97 if (obj1.baseos7) op8b = obj1.baseos7.value;98 if (obj1.baseon8) op9a = obj1.baseon8.value;99 if (obj1.baseos8) op9b = obj1.baseos8.value;100 if (obj1.baseitn) itmn = obj1.baseitn.value;101 for (i=0; i<obj1.length; i++) { // run entire form102 obj = obj1.elements[i]; // a form element108 if (obj.type == "select-one") { // just selects109 if (obj.name == "quantity" ||110 obj.name == "amount") continue;111 pos = obj.selectedIndex; // which option selected112 val = obj.options[pos].value; // selected value113 ChkTok (obj1); // check for any specials115 if (obj.name == "on0" || // let this go where it wants116 obj.name == "os0" ||117 obj.name == "on1" ||118 obj.name == "os1" ||119 obj.name == "on2" ||120 obj.name == "os2" ||121 obj.name == "on3" ||122 obj.name == "os3" ||123 obj.name == "on4" ||124 obj.name == "os4" ||125 obj.name == "on5" ||126 obj.name == "os5" ||127 obj.name == "on6" ||128 obj.name == "os6" ||129 obj.name == "on7" ||130 obj.name == "os7" ||131 obj.name == "on8" ||132 obj.name == "os8" ||133 obj.name == "on9" ||134 obj.name == "os9") continue;136 StorVal ();138 } else139 if (obj.type == "checkbox" || // just get checkboxex140 obj.type == "radio") { // and radios141 if (obj.checked) {142 val = obj.value; // the value of the selection143 ChkTok (obj1);144 StorVal ();145 }146 } else147 if (obj.type == "select-multiple") { //one or more148 for (j=0; j<obj.options.length; j++) { // run all options149 if (obj.options[j].selected) {150 val = obj.options[j].value; // selected value (default)151 ChkTok (obj1);152 StorVal ();153 }154 }155 } else156 if ((obj.type == "text" || // just read text,157 obj.type == "textarea") &&158 obj.name != "tot" && // but not from here159 obj.name != "quantity") {160 val = obj.value; // get the data161 //if (val == "" && tst)162 //{ // force an entry163 // alert ("Enter data for " + obj.id);164 // return false;165 //}166 StorVal ();167 }168 }169 // Now summarize stuff we just processed, above170 if (op1a.length > 0) obj1.on0.value = op1a;171 if (op1b.length > 0) obj1.os0.value = op1b;172 if (op2a.length > 0) obj1.on1.value = op2a;173 if (op2b.length > 0) obj1.os1.value = op2b;174 if (op3a.length > 0) obj1.on2.value = op3a;175 if (op3b.length > 0) obj1.os2.value = op3b;176 if (op4a.length > 0) obj1.on3.value = op4a;177 if (op4b.length > 0) obj1.os3.value = op4b;178 if (op5a.length > 0) obj1.on4.value = op5a;179 if (op5b.length > 0) obj1.os4.value = op5b;180 if (op6a.length > 0) obj1.on5.value = op6a;181 if (op6b.length > 0) obj1.os5.value = op6b;182 if (op7a.length > 0) obj1.on6.value = op7a;183 if (op7b.length > 0) obj1.os6.value = op7b;184 if (op8a.length > 0) obj1.on7.value = op8a;185 if (op8b.length > 0) obj1.os7.value = op8b;186 if (op9a.length > 0) obj1.on8.value = op9a;187 if (op9b.length > 0) obj1.os8.value = op9b;188 if (itmn.length > 0) obj1.item_number.value = itmn;189 obj1.item_name.value = des;190 obj1.amount.value = Dollar (amt);191 if (obj1.tot) obj1.tot.value = "$" + Dollar (amt);192 }