I am trying to add multiple values to a hidden field. It's working fine, but I want the values which are getting added in the hidden field to be unique and not to get added if a value is entered more than once.
interestedin is the name of the selectbox where the values are selected and interest is the id of the hiddenfield where the values are getting added as comma separated values while selecting options in the selectbox.
if a same option is selected twice, it's getting added in the hidden field twice. I don't want any values to get added in the hidden fields though its selected twice.
the function clicker is called while selecting the values in the select box(name="interestedin") and the values will be added in the hidden field (id="interest")
function clicker(){
var itemsobj=document.getElementsByName("interestedin[]");
str='';
//alert(itemsobj[0].value);
//alert('test');
count=0;
var arr = new Array();
for(var i=0;i<itemsobj.length;i++)
{
count += 1;
str +=itemsobj[i].value+',';
//alert(str);
arr[i] = itemsobj[i].value;
}
var length=str.length;
var strr=str.substring(0,length-1);
document.getElementById('interest').value = strr;
//alert(strr);
setProductPrice(arr,count);
}