I wrote a simple _javascript_
to calculate unit * qty and produce a line for each row that is dynamically
created. The problem is that I can’t
get the extTotal value formatted as 2 digit decimal. Apparently,
the eval()
function doesn’t take any precision nor can I call a function from within
the eval function. I am beating my head against the
computer trying to figure out what seems relatively simple… Any _javascript_s
gurus have any thoughts??? <SCRIPT LANGUAGE='_javascript_'> <!-- Raise the Bat shields! function calculateLine() { // for this script I hard coded the 2 // var rows=@@local$rowcnt var taxLineArray
= new Array(); for (var i
= 0; i <
2 ; i++) { cnt = i
+1; taxLineArray[i] = (eval("document.bform.prodTotal" + cnt
+ ".value") * eval("document.bform.unit" + cnt +
".value")); eval("document.bform.extTotal" + cnt
+ ".value=" + taxLineArray[i]); } } // down shields! --> </SCRIPT> <FORM NAME="bform"
ACTION="" METHOD=POST > <input type=text value="1.99"
name="prodTotal1"> <input type=text value=".5"
name="unit1" onBlur='calculateLine();'> <input type=text value=""
name="extTotal1"> <P> <input type=text value="1.99"
name="prodTotal2"> <input type=text value=".5"
name="unit2" onBlur='calculateLine();'> <input type=text value=""
name="extTotal2"> </form> I have tried to format the number before
the eval()
function, but the eval function looses the
function. I have also tried calling
the following functions.. function cent(amount){ return (amount == Math.floor(amount))
? amount + '.00' : ( (amount*10 == Math.floor(amount*10))
? amount + '0' : amount); } function clnNum(amount) { return cent(Math.round(amount*Math.pow(10,2))/Math.pow(10,2)); } ________________________________________________________________________ TO UNSUBSCRIBE: Go to http://www.witango.com/maillist.taf ________________________________________________________________________ TO UNSUBSCRIBE: Go to http://www.witango.com/maillist.taf |
- Witango-Talk: Test. Pls. ignore [EMAIL PROTECTED]
- Re: Witango-Talk: [OT] Javascript eval() Brad Robertson
- Re: Witango-Talk: [OT] Javascript eval() Alan Wolfe
- Re: Witango-Talk: [OT] Javascript eval() Bradley J. Robertson
- RE: Witango-Talk: [OT] Javascript eval() Scott Cadillac
- Re: Witango-Talk: [OT] Javascript eval() Bradley J. Robertson