Crear y borrar elementos

[ permalink ] [ download ]
function gehituBestePartaidea(fieldset)
{
   var ol = gebi(fieldset).getElementsByTagName("ol")[0];

   the_fieldset = gebi(fieldset);
   var counter = parseInt(the_fieldset.counter) + 1;
   the_fieldset.counter = counter;

   new_li_id =        fieldset+'_li_partaidea_'+counter;
   new_control_id =   fieldset+'_partaidea_'+counter;
   new_control_name = fieldset+'_partaideak:list';
   new_image_id =     fieldset+'_image_partaidea_'+counter;
   new_button_id =    fieldset+'_button_partaidea_'+counter;

   var new_li = cebn('li');
   new_li.setAttribute('id',new_li_id);

//  nando: antes un input text, ahora un select
//
//   var new_input = cebn('input');
//   new_input.setAttribute('type','text');
//   new_input.setAttribute('id',new_control_id);
//   new_input.setAttribute('name',new_control_name);
//   new_li.appendChild(new_input);

   var new_div = cebn('div')
   new_div.setAttribute('id',new_image_id);
   new_li.appendChild(new_div);

   var new_select = cebn('select');
   new_select.setAttribute('id',new_control_id);
   new_select.style.width = "300px";
   new_select.setAttribute('name',new_control_name);
   new_li.appendChild(new_select);

   new_span = cebn('span');
   new_span.setAttribute('class','derrigorrez');
   new_span.innerHTML = '*';
   new_span.style.color = 'red';
   new_span.style.fontWeight = 'bold';
   new_span.style.fontSize = '1.4em';
   new_span.style.marginLeft = '5px';
/*   new_span.style.verticalAlign = 'center';*/
   new_li.appendChild(new_span);


   var new_input = cebn('input');
   new_input.setAttribute('type','button');
   new_input.setAttribute('id',new_button_id);
   new_input.setAttribute('value',"<dtml-var expr="getins('cancel')">");
   new_li.appendChild(new_input);

   ol.appendChild(new_li);

   // dynamic functions ******************************************************

   var new_select = gebi(new_control_id);
   var instruction = "partaide_berria_gehitu('"+fieldset+"','"+new_li_id+"','"+new_control_id+"')";
   new_select.instruction = instruction;
   new_select.onchange = function() { eval(this.instruction); }

   var new_input = gebi(new_button_id);
   var instruction = "ezabatuBestePartaidea('"+fieldset+"','"+new_li_id+"')";
   new_input.instruction = instruction;
   new_input.onclick = function() { eval(this.instruction); }

   select_create(new_control_id,new_image_id);

   return -1;
}

function ezabatuBestePartaidea(fieldset, li)
{
   if (confirm('<dtml-var expr="getins('Ziur zaude?')">'))
   {
     var ol = gebi(fieldset).getElementsByTagName("ol")[0];
     old_li = gebi(li);
     ol.removeChild(old_li);
   }
   return -1;
}
hits counter