Behaviour.register({ '.naction_remove_hash': function(el) { el.onclick = function(){ //remove a hash list item parentEl = el while(parentEl.tagName != 'LI'){ parentEl = parentEl.parentNode } Element.remove(parentEl); return false; } }, '.naction_add_hash': function(el) { el.onclick = function() { //add a hash list item ulEl = $(el.id+'_list'); newkey = $(el.id+'_key').value; if(newkey.length > 0){ new Ajax.Request('../hash_tag_item/'+el.id+'/'+newkey+'/'+$(el.id+'_value').value, { asynchronous:true, onComplete: function(t){ ulEl.innerHTML += t.responseText; Behaviour.apply(); } }); } return false; } }, '.naction_remove_rel': function(el) { el.onclick = function() { //remove rel from list and add option to pulldown parentEl = el while(parentEl.tagName != 'LI'){ parentEl = parentEl.parentNode } rel_oid = parentEl.getElementsByTagName('input')[0].value; rel_name = parentEl.getElementsByTagName('input')[0].name.substr(0, parentEl.getElementsByTagName('input')[0].name.length-2); rel_display = parentEl.getElementsByTagName('span')[0].innerHTML; newOpt = document.createElement('option'); newOpt.value = rel_oid; newOpt.appendChild(document.createTextNode(rel_display)); $(rel_name+'_selector').appendChild(newOpt); Element.remove(parentEl); return false; } }, '.naction_add_rel': function(el) { el.onclick = function() { //add a relation list item and remove item from options ulEl = $(el.id+'_list'); selectorEl = $(el.id+'_selector'); // TODO: moz allows a select box with 0 options in it? ... disabled must be set with js selectedElement = selectorEl.options[selectorEl.selectedIndex] sURL = '../relation_item/'+el.id+'/'+selectedElement.innerHTML+'/'+selectedElement.value new Ajax.Request(sURL, { asynchronous:true, onComplete: function(t){ ulEl.innerHTML += t.responseText; Behaviour.apply(); }, onFailure: function(t){ // TODO: put the rel back in the option list // chrisfarms: UNTESTED... selectedEl might not be availible? // prob wont work in ffox. since moz doesnt like innerHTML used like this with options selectorEl.innerHTML += '' } }); Element.remove(selectedElement); return false; } } });