Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Ana Belén Ramón http://www.avidos.net/detalles

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Input and textarea preview

Preview what you type in an input or a textarea out of them (in a html tag, like a p, hx...)

Seen here: http://amuchamu.bitacoras.com/archivos/2005/02/17/previsualizacion_de_comentarios (spanish explain).

javascript code:

   1  
   2  function preview(id1, id2){
   3  	  		var NewText = document.getElementById(id1).value;
   4  	  		splitText = NewText.split(/\n/).join("<br />");
   5  	  		var DivElement = document.getElementById(id2);
   6  	  		DivElement.innerHTML = splitText;
   7  }
   8  


html code:

   1  
   2  <form action="#">
   3  <label>Name:</label>
   4  <input type="text" id="nombre" onkeyup="preview('name', 'preview-name');" />
   5  
   6  <label>Phone:</label>
   7  <input type="text" id="phone" onkeyup="preview('phone', 'preview-phone');" />
   8  </form>
   9  
  10  <h2>Preview</h2>
  11  <dl>
  12  	<dt>Name:</dt>
  13  	<dd id="preview-name"></dd>
  14  	<dt>Phone:</dt>
  15  	<dd id="preview-phone"></dd>
  16  
  17  </dl>
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS