Ver Mensaje Individual
  #9 (permalink)  
Antiguo 17/11/2010, 15:07
Jarkaos
 
Fecha de Ingreso: noviembre-2002
Ubicación: Suecia
Mensajes: 253
Antigüedad: 21 años, 5 meses
Puntos: 2
Respuesta: Donde encuentro un tutorial para esto:

Bueno he agregado los botones y he creado una funcion para cancelar los cambios, pero...
al hacer click en el boton cancelar obtengo este error:

textarea.parentNode no esta definido

Que esta mal?:

Código Javascript:
Ver original
  1. function inPlaceEditor (editableElement) {
  2.         editableElement.onclick = function() {
  3.             //Getting the text from the p-element
  4.             var text = editableElement.firstChild.nodeValue;
  5.            
  6.             // create and style the textarea element
  7.             var textarea = document.createElement('textarea');
  8.                 textarea.setAttribute('cols', config.cols);
  9.                 textarea.setAttribute('rows', config.rows);
  10.                 textarea.style.width = "100%";
  11.            
  12.             // Create the text for the textarea (the same text saved from p-elemnt)
  13.             var nyText = document.createTextNode(text);
  14.            
  15.             // Put all together
  16.             textarea.appendChild(nyText);
  17.            
  18.             //Replace the p-element with the newly created textarea
  19.             editableElement.parentNode.replaceChild(textarea, editableElement);
  20.            
  21.             //Creating and styling the buttons
  22.             var editbutton = document.createElement('input');
  23.                 editbutton.setAttribute('type', 'button');
  24.                 editbutton.setAttribute('value', config.okButtonText);
  25.                 editbutton.setAttribute('onclick', 'edit();');
  26.            
  27.             var cancelbutton = document.createElement('input');
  28.                 cancelbutton.setAttribute('type', 'button');
  29.                 cancelbutton.setAttribute('value', config.cancelButtonText);
  30.                 cancelbutton.setAttribute('onClick', 'cancel();');
  31.            
  32.             //Setting the buttons on the page
  33.             textarea.parentNode.insertBefore(cancelbutton, textarea.nextSibling);
  34.             textarea.parentNode.insertBefore(editbutton, textarea.nextSibling);
  35.            
  36.         };
  37.     };
  38.    
  39.     function cancel(){
  40.         var textarea = document.getElementsByTagName('textarea');
  41.         var text = textarea.value;
  42.         var pElement = document.createElement('p');
  43.             pElement.setAttribute('class', 'editable');
  44.         var original = document.createTextNode(text);
  45.         pElement.appendChild(original);
  46.        
  47.         textarea.parentNode.replaceChild(pElement, textarea);
  48.     };