1

I'm having some javascript issues with some legacy code, since my company is attempting to upgrade to IE11 from IE8. I have a piece of javascript that finds all commas in a field and replaces it with a couple characters, it is as follows:

document.frm.txt_fieldValue[1].value = 
document.frm.txt_fieldValue[1].value.replace(/,/gi, "$0");

In my code this is all on one line, however. This code works in IE8, Chrome, and Firefox. However, in IE9+, specifically IE11 (since this is what my company is upgrading to), this code doesn't replace any commas. I can get it to replace a single comma by using the following code:

document.frm.txt_fieldValue[1].value = 
document.frm.txt_fieldValue[1].value.replace(",", "$0");

Because I replaced a single comma, I know my code is reached. But I have searched around and I have yet to find a solid answer. Does anyone else have this problem? If so, has anyone found a solution?

Thanks!

10
  • 1
    could you provide a jsfiddle? Additionally, maybe it is an assignment issue. Try var myValue=document.frm.txt_fieldValue[1].value.replace(/,/gi, "$0"); document.frm.txt_fieldValue[1].value = myValue; Commented Oct 16, 2014 at 15:04
  • 1
    Have you tried to escape the comma? Commented Oct 16, 2014 at 15:13
  • @E.Maggini I've never used Jfiddle. Trying to get it to work. I did try the assignment value, but that didn't work. Commented Oct 16, 2014 at 15:32
  • @MarcoCI I can try that. That does seem to work. It will require a decent rewrite of the page, but it should work. Thanks! Commented Oct 16, 2014 at 15:33
  • 1
    Then you have to replace it with "$$0". I doubt if this code ever worked properly, on any browser. Commented Oct 16, 2014 at 16:17

2 Answers 2

2

You need to replace it with "$$0", which after escaping will turn into a real $0. I doubt if this code ever worked properly, on any browser.

Sign up to request clarification or add additional context in comments.

Comments

1

I recently fixed a bug that might help.

If your value that you were replacing was 0 -- as a value, not a string -- IE11 would only append the replacement string instead of actually replacing it.

Here's what I was working with:

buf = buf.replace( /%%TOTALAMOUNT%%/gim, "$" + parseFloat( g_UserPurchases[LCV].CurrencyValue.val() ).toFixed(2) );                        

This printed: "%%TOTALAMOUNT%%.00"

I fixed it by checking:

if( ( g_UserPurchases[LCV].CurrencyValue.val() == 0 ) || ( g_UserPurchases[LCV].CurrencyValue.val() === 0 ) ){
//IE fix: IE did not like the $ character and didn't replace if val = 0
buf = buf.replace( /%%TOTALAMOUNT%%/gim, "$0.00");    }

Please note: IE11 didn't replace the the dollar sign character, $. So, I used the character code instead:

$

Hope this helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.