IE9 javascript replace does not work

advertisements

I have a string such as "Value = $val$" and I want to replace $val$ with some value like "$0.00"

so final string can look like "Value = $0.00"

This works in firefox and IE 7 and IE 8 but does not work in IE 9 any idea why? and how I can resolve the issue?

Any value other than $0.00 (e.g.$5.00) works without any issue.

http://jsfiddle.net/jhdVV/5/

edit: updated link with a textbox and a button to test with diff values.

http://jsfiddle.net/jhdVV/10/

In IE 9 I am getting "Value =$val$.00"

Browser is in Standards mode.

Note: I am working on legacy code so , ideally I would like to stay away from tempting jquery solutions.


The $0 in your replacement text is essentially an uninitialized variable, the behavior of which is undefined. So, escape the dollar sign:

$$0.00