Want to add a value and remove on a single click using javascript or jquery
<p>I am using a onclick function and adding a value to by paasing a value to it. If the value already exists den i remove that value from the list.</p>

<pre><code>function send_value(str)
    {
    //alert(str);
    var sub_id = document.getElementById('selected_sub_id').value;
    //alert(sub_id.indexOf(str));
    if(sub_id.indexOf(str)==-1)
    {
        if(sub_id=="")
        {
            sub_id+=str;
        }
        else
        {
        sub_id+=',';
        sub_id+=str;
        }
    }
    else
    {
        sub_id = sub_id.replace(str+",", "");
        sub_id = sub_id.replace(","+str, "");
        sub_id = sub_id.replace(str, "");
    }
    //alert(sub_id);
    document.getElementById('selected_sub_id').value=sub_id;
}
</code></pre>

<p>This is the function. Suppose i have the values 1,2,3,4 in the <code>selected_sub_id</code> and i am passing 5 to it, it will be stored as 1,2,3,4,5
now i am passing 24 it will be stored as 1,2,3,4,5,24
No suppose i want to remove 2, so when i send 2 to the function it removes all the occurrences of 2 so i am left with only 1,3,4,54...
kindly help me with this thanks in advance..</p>
