Link to home
Start Free TrialLog in
Avatar of marklorenz
marklorenzFlag for United States of America

asked on

"undefined" when using innerHTML in IE 6

I have a problem where my the attached JS function gives me this in FF 3: "4,593.75", but gives me this in IE 6: "undefined,undefinedundefinedundefined.75"

I have stepped through the function and it is doing it's job properly, but IE won't show the digits properly.  All I'm trying to do is to insert commas in appropriate places for monetary values.

Has anyone run into this before? Is there a workaround for IE 6?
(DECLARATION)
function toMonetaryString(x) {	//put in commas where needed, allow for decimal point
  var _x=x.toString();
  var _len=_x.length 1;
  var dot=_x.indexOf('.');
  var _ret="";
  var _start = 0;
  if( dot >= 0 ) {
	_start = dot-1;
	_ret = _x.substr(dot,_x.length);
  }
  var _cnt = 0;
  for(var i=_start;i>=0;i--) {
	_ret=_x[i] _ret;
	_cnt  ;
	if(!(_cnt%3)) {
	  _ret="," _ret;
	  _cnt = 0;
	}
  }
  return _ret;
			}
... (USAGE)
	  var additionalPeople = parseInt(selectedHouseholdSize) - 12;
	  var amt = (5743.75   (additionalPeople * 975.00));
	  var roundedAmt = Math.round(amt*100)/100;
	  btoaLimitAmt = toMonetaryString(roundedAmt);
	}
	document.getElementById('btoaIncomeLimit').innerHTML = btoaLimitAmt;
... (HTML)
    Is your household MONTHLY gross income at or below $ <span id="btoaIncomeLimit"></span>&nbsp;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hard2u2001
hard2u2001

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Now see, if those other browsers would just support VBScript, it would be as simple as
btoaLimitAmt = FormatCurrency(roundedAmt)
Avatar of marklorenz

ASKER

Thanks for the fast answer!  You are right - works in IE 6 as well as the always better FF.