• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 453
  • Last Modified:

"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

0
marklorenz
Asked:
marklorenz
1 Solution
 
hard2u2001Commented:
you can try this function... this works fine for me in both ie and ff
//Function
function formatNumber(options)
 {
	options.number = options.number||'0';
        options.prefix= options.prefix||'';
        options.precision= options.precision||'0';
        options.suffix= options.suffix||'';
 
	if(isNaN(parseFloat(options.number)))
	{
		return "";
	}
	options.number = parseFloat(options.number).toFixed(options.precision);
	options.number+= '';
	var x = options.number.split('.');
	var x1 = x[0];
	var x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return options.prefix+x1 + x2+options.suffix;
 }
//Usage
formatNumber({number:"4593.75",prefix:"$",precision:"2"})

Open in new window

0
 
dan_nealCommented:
Now see, if those other browsers would just support VBScript, it would be as simple as
btoaLimitAmt = FormatCurrency(roundedAmt)
0
 
marklorenzAuthor Commented:
Thanks for the fast answer!  You are right - works in IE 6 as well as the always better FF.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now