rish
rish

Reputation: 215

Issues in remove comma in javascript

When i entered only one email id, and check in inspecter, it shows like this

I need to remove commas,if i enter only one id and it need to show commas, if i enter one more or multiple id's given it shows comma. Can you please help ?

function GetTextValue() {

    $(divValue).empty(); 
    $(divValue).remove(); values = '';
    values += this.value + ','
    });
    document.all.contact_list.value = values;
}

Upvotes: 1

Views: 73

Answers (3)

ozil
ozil

Reputation: 7117

function GetTextValue() {
    $(divValue).empty();
    $(divValue).remove(); 
    var values = '';

    $('.input').each(function() {
        divValue = $(document.createElement('div')).css({padding:'5px', width:'200px'});
       if(this.value != '') {
           values += this.value;
           values += ',';
       }
    });
    document.all.contact_list.value = value.substring(0, value.length - 1);//remove last comma
}

Upvotes: 1

Arkar Aung
Arkar Aung

Reputation: 3584

You can do it like that.

function GetTextValue() {

    $(divValue).empty(); 
    $(divValue).remove(); values = '';

    $('.input').each(function() {
        divValue = $(document.createElement('div')).css({
            padding:'5px', width:'200px'
        });
        if (this.value == '') {
           // alert('Empty');
        } else if (values != '') {
            values += ',';
        }
        values += this.value;
    });
    document.all.contact_list.value = values;
}

JSFiddle

Hope it will be useful for you.

Upvotes: 2

Jose Ricardo Bustos M.
Jose Ricardo Bustos M.

Reputation: 8164

function GetTextValue() {
    $(divValue).empty();
    $(divValue).remove(); 
    var values = '';

    $('.input').each(function() {
        divValue = $(document.createElement('div')).css({
            padding:'5px', width:'200px'
        });
        if(this.value.trim() != ''){
            if(values != ''){
                values += ',';
            }
            values += this.value.trim();
        }
    });
    document.all.contact_list.value = values;
}

Upvotes: 1

Related Questions