1

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;
}
0

3 Answers 3

2

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.

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

7 Comments

Alert if this.value is empty ??
Shouldn't that be if (this.value != '') - he only wants to add commas if there is another value, so checking if values is not empty will add extra commas on the end
is this right? if (values != '') { alert('text'); values += ','; } thanks
sorry, how to test, if i enter more email id with using alert? thanks
@rish I added JSFiddle link to test it. Thanks
|
1
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;
}

Comments

1
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
}

1 Comment

It will be ended with comma like a,b,c,

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.