Ver Mensaje Individual
  #4 (permalink)  
Antiguo 10/10/2010, 07:49
Avatar de _cronos2
_cronos2
Colaborador
 
Fecha de Ingreso: junio-2010
Mensajes: 2.062
Antigüedad: 13 años, 11 meses
Puntos: 310
Respuesta: Abrir un TextArea al hacer click sobre una caja de texto

Prueba así:
Código Javascript:
Ver original
  1. function camb(c){
  2.  switch (c.nodeName.toLowerCase()){
  3.   case 'input':
  4.    var t=document.createElement('textarea');
  5.    t.setAttribute('cols','20');
  6.    t.setAttribute('rows','5');
  7.    t.setAttribute('id','tarea'+c.id.substr(1,c.id.length-1));
  8.    t.setAttribute('name','tarea'+c.name.substr(1,c.name.length-1));
  9.    t.setAttribute('onblur','camb(this);');
  10.    t.value = c.value;
  11.    c.form.insertBefore(t,c.nextSibling);
  12.    t.focus();
  13.   break;
  14.   case 'textarea':
  15.    var i=document.createElement('input');
  16.    i.setAttribute('type','text');
  17.    i.setAttribute('id','c'+c.id.substr(5,c.id.length-1));
  18.    i.setAttribute('name','c'+c.name.substr(5,c.name.length-1));
  19.    i.setAttribute('onfocus','camb(this);');
  20.    i.value = c.value;
  21.    c.form.insertBefore(i,c);
  22.   break;
  23.  }
  24.  c.parentNode.removeChild(c);
  25. }
Código HTML:
Ver original
  1. <form name="a" action="" method="post">
  2. <input type='text' id="c1" name='c1' onfocus="camb(this);" />
  3. <br />
  4. <input type="text" id="c2" name="c2" onfocus="camb(this);" />
  5. <br />
  6. <input type="submit" value="Enviar" />
  7. </form>
En vez de ocultar y mostrar los campos, los vas borrando y creando. Esto es más útil porque sino aunque esté oculto te llegan los resultados del input y el textarea.
Saludos (:
__________________
" Getting older’s not been on my plans
but it’s never late, it’s never late enough for me to stay. "
Cigarettes - Russian Red