OK, I haven't tried it at all, but maybe try this code instead of what you originally posted:
Code:
<script type="text/javascript">
function contains(a, ele) {
for (var i = 0; i < a.length; i++) {
if (a[i] == ele) {
return true;
}
}
return false;
};
function remove(a, ele) {
var arr = new Array();
var count = 0;
for (var i = 0; i < a.length; i++) {
if (a[i] != ele) {
arr[count] = a[i];
count++;
}
}
return arr;
};
window.onload = function () {
var taglist = document.getElementById('tags');
taglist.value = taglist.value.replace (/\s+/g,''); // strip space
var tags = taglist.value.split(',');
var populartags = document.getElementById('popularTags').getElementsByTagName('span');
for (var i = 0; i < populartags.length; i++) {
if (contains(tags, populartags[i].innerHTML)) {
populartags[i].className = 'selected';
}
}
}
function doTag(ele) {
var thisTag = ele.innerHTML;
var taglist = document.getElementById('tags');
var tags = taglist.value.split(',');
// If tag is already listed, remove it
if (contains(tags, thisTag)) {
tags = remove(tags, thisTag);
ele.className = 'unselected';
// Otherwise add it
} else {
tags.splice(tags.length-1, 0, thisTag);
ele.className = 'selected';
}
taglist.value = tags.join(',');
document.getElementById('tags').focus();
}
</script>