I have a hidden field and I add string to it, separated by semicolon. How I can I check the duplication when adding a new string?
I am doing as
function AddToHiddenField(source, hdnFiledId)
{
var srcList = document.getElementById(source);
var hdnFieldSubstring = document.getElementById(hdnFieldId);
var len = srcList.length;
hdnFieldSubstring.value = '';
for(var i = 0; i < len; i++)
{
if (srcList.options[i] != null)
{
if (hdnFieldSubstring.value == "")
{
hdnFieldSubstring.value = srcList.options[i].text;
}
else
{
hdnFieldSubstring.value = hdnFieldSubstring.value + ";" + srcList.options[i].text;
}
}
}
}
How can I check a string already exists in hdnFieldSubstring before added to it (in javascript)?