lulu50
asked on
Remove double comma upon executing my Jquery code
Hi,
I have a textarea with the following list in it 736 4937 587 795 955
1. enter this list in a textarea 736 4937 587 795 955
2.. run my jquery: the output will be this 736, 4937, 587, 795, 955
3. now the user decide to run my jquery again: the user will get this output for running my query again 736,, 4937,, 587,, 795,, 955
4. How can I fix the jquery to say:
if the data in my textarea already has a comma and space between them then don't do anything.
only separate my list if there is no comma followed by a space between them.
I just don't wont the double comma if the user kept on clicking the button.
Thank you for your help,
Lulu50
I have a textarea with the following list in it 736 4937 587 795 955
1. enter this list in a textarea 736 4937 587 795 955
2.. run my jquery: the output will be this 736, 4937, 587, 795, 955
var str = $('#ItemList').val();
str = $('#ItemList').val().replace(/(?:\r\n|\r|\n|\s)/g, ', ');
$('#ItemList').val(str);
3. now the user decide to run my jquery again: the user will get this output for running my query again 736,, 4937,, 587,, 795,, 955
4. How can I fix the jquery to say:
if the data in my textarea already has a comma and space between them then don't do anything.
only separate my list if there is no comma followed by a space between them.
I just don't wont the double comma if the user kept on clicking the button.
Thank you for your help,
Lulu50
ASKER
leakim971
it looks good!!!
how can I say don't put comma on the last white space
so if I add a white space at the end of my list I'll get this
736, 4937, 587, 795, 955,
I want to say don't put any comma at the end of the list.
it looks good!!!
how can I say don't put comma on the last white space
so if I add a white space at the end of my list I'll get this
736, 4937, 587, 795, 955,
I want to say don't put any comma at the end of the list.
var str = $('#ItemList').val();
if (str.indexOf(",") < 0)
str = $('#ItemList').val().replace(/(?:\r\ n|\r|\n|\s )/g,', ');
$('#ItemList').val(str);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
leakim971
That is fabuleux my friend!!!!!
Thank you for all your help!!!!
That is fabuleux my friend!!!!!
Thank you for all your help!!!!
ASKER
bravo comme toujours!!!
Merci beaucoup
Merci beaucoup
Open in new window