Facebook
From justii1311, 6 Years ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 261
  1. function selectVademecums(select)
  2. {
  3.   var option = select.options[select.selectedIndex];
  4.   var ul = select.parentNode.getElementsByTagName('ul')[0];
  5.      
  6.   var choices = ul.getElementsByTagName('input');
  7.   for (var i = 0; i < choices.length; i++)
  8.     if (choices[i].value == option.value)
  9.       return;
  10.      
  11.   var li = document.createElement('li');
  12.   var input = document.createElement('input');
  13.   var text = document.createTextNode(option.firstChild.data);
  14.      
  15.   input.type = 'hidden';
  16.   input.name = 'lista[]';
  17.   input.value = option.value;
  18.  
  19.   li.appendChild(input);
  20.   li.appendChild(text);
  21.   li.setAttribute('onclick', 'this.parentNode.removeChild(this);');    
  22.    
  23.   ul.appendChild(li);
  24. }