Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  175] [ 5]  / answers: 1 / hits: 156452  / 15 Years ago, sun, december 27, 2009, 12:00:00

I have this



 var date = $('#Date').val();


this get the value in the textbox what would look like this



12/31/2009



Now I do this on it



var id = 'c_' + date.replace(/, '');


and the result is



c_1231/2009



It misses the last '/' I don't understand why though.


More From » jquery

 Answers
20

You need to set the g flag to replace globally:



date.replace(new RegExp(/, g), '')
// or
date.replace(///g, '')


Otherwise only the first occurrence will be replaced.


[#97976] Wednesday, December 23, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristinadomoniquel

Total Points: 320
Total Questions: 94
Total Answers: 94

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
cristinadomoniquel questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
Mon, Nov 23, 20, 00:00, 4 Years ago
Mon, Aug 17, 20, 00:00, 4 Years ago
;