1

I'm using this to insert some string data:

$("#edit_order #"+key).val(value.replace('+',' ')); 

However, the second instance of "+" is not being replaced with this string:

123123123+APT+123

Instead I get the output:

123123123 APT+123
Jon Lachonis
  • 911
  • 1
  • 8
  • 18

2 Answers2

5

Use:

value.replace(/\+/g, ' ')

g is a global match flag and will cause your replace to match all instances of +.

Halcyon
  • 57,230
  • 10
  • 89
  • 128
1

Try ...

$("#edit_order #"+key).val(value.replace(/\+/g,' '));

To replace all, your value "to replace" must be defined as a regular expression.

Here's a jsFiddle

rfornal
  • 5,072
  • 5
  • 30
  • 42