Foros del Web » Programando para Internet » Javascript »

Generar codigo html desde form

Estas en el tema de Generar codigo html desde form en el foro de Javascript en Foros del Web. Hola. Estoy interesado en hacer un codigo en javascript que llamado desde un formulario y pasandole desde este unos ciertos valores, pueda generarme un codigo ...
  #1 (permalink)  
Antiguo 01/08/2006, 11:55
Avatar de iv19an  
Fecha de Ingreso: septiembre-2004
Mensajes: 44
Antigüedad: 19 años, 7 meses
Puntos: 0
Generar codigo html desde form

Hola.

Estoy interesado en hacer un codigo en javascript que llamado desde un formulario y pasandole desde este unos ciertos valores, pueda generarme un codigo html para poder copiar y pegar en otro sitio.

Lo que tengo hasta ahora es lo siguiente:

index.html
Código:
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script type="text/javascript" src="javascript/script.js"></script>
<body>
<form id="rbb" name="rbb" action="" enctype="text/plain">
<table width="100%"  border="1">
   <tr>
    <td align="center" colspan="2"><strong>Codigo HTML para Noticias DaloTodoyMas.com</strong></td>  
  </tr>
  <tr>
    <td width="20%">Titulo Pelicula:</td>
    <td width="75%"><input type="text" name="titulo" id="titulo"></td>
    </tr>
  <tr>
    <td>Enlace a Pelicula: </td>
    <td><input type="text" name="enlace" id="enlace" width="200"></td>
    </tr>
  <tr>
    <td>Enlace a Imagen de Pelicula: </td>
    <td><input type="text" name="imagen" id="imagen" width="200"></td>
    </tr>
   <tr>
    <td>Genero:</td>
    <td><input type="text" name="genero" id="genero"></td>
    </tr>
   <tr>
    <td>Pa&iacute;s:</td>
    <td><input type="text" name="pais" id="pais"></td>
    </tr>
   <tr>
    <td>A&ntilde;o:</td>
    <td><input type="text" name="ano" id="ano"></td>
    </tr>
   <tr>
    <td>Duraci&oacute;n:</td>
    <td><input type="text" name="duracion" id="duracion"></td>
    </tr>
   <tr>
    <td>Puntuaci&oacute;n IDMB: </td>
    <td><input type="text" name="puntuacion" id="puntuacion"></td>
    </tr>
   <tr>
    <td>Sinopsis:</td>
    <td><input type="text" name="sinopsis" id="sinopsis" height="200" width="200"></td>
    </tr>
   <tr><div id="botonGenera">
    <td align="center" colspan="2"><input type="button" value=" Generar Codigo " onClick="javascript:GeneraDocumentoHTML()">&nbsp;<input name="reset" type="reset" value="Borrar todo"></td>
   </tr></div></table>


<h2><label for="contenidoGenerado">Codigo HTML generado:</label></h2>
<div id="dcontenidoGenerado">
<textarea cols="100" rows="35" name="contenidoGenerado" id="contenidoGenerado"></textarea>
</form>
</div>
</body>
</html>
Y en el script.js tengo:

Código:
caracteresTransformables = new Array("á","é","í","ó","ú","Á","É","Í","Ó","Ú","ñ","Ñ","Ä","ÇË","Ï","Ö","Ü","ä","ç","ë","ï","ö","ü","‘","’","“","”","„","‰","%","$","¥","£","€","#","™","&","<",">","…","÷","÷","×","¿","»","¶","±","«","©","§","¡","®","•","*")

longitudArray=caracteresTransformables.length
var output="";

/*Transforma los caracteres no ascii a números de entidades válidos para xml*/
function funcion(contenidoFormulario)
	{
		var input=contenidoFormulario;
		longitudInput=input.length;
		var reemplazado=false;
		output="";
		for (var i=0; i< longitudInput; i++)
			{
				reemplazado=false;
				for (var j=0; j< longitudArray; j++)
					{
						if (input.charAt(i)==caracteresTransformables[j])
							{
								output=output+"&#"+input.charCodeAt(i)+";"
								reemplazado=true;
							}
					}

				if (reemplazado==false)
					{
						output=output+input.charAt(i);
					}
			}
	}

function GeneraDocumentoHTML()
	{
/*Inicio del documento HTML*/
document.rbb.contenidoGenerado.value="";
document.rbb.contenidoGenerado.value='<table align="center" width="90%"  border="1">'
+'\n'+'<tr>'
+'\n'+'<td width="28%" rowspan="7"><div align="center">'+'\n'

funcion(document.rbb.enlace.value)
if (document.rbb.enlace.value !="")
	{
		document.rbb.contenidoGenerado.value=document.rbb.contenidoGenerado.value+'<a href="'+output+'" target="_blank"><img src="'
	}
	
funcion(document.rbb.imagen.value)
if (output!="")
	{
		document.rbb.contenidoGenerado.value=document.rbb.contenidoGenerado.value+output+'" width="120" height="180" border="2" title="'
	}

funcion(document.rbb.titulo.value)
if (output!="")
	{
		document.rbb.contenidoGenerado.value=document.rbb.contenidoGenerado.value+output+'"></img></a></div></td>'
	}
+'\n'+'<td width="15%">'
+'Titulo:</td>'
+'\n'+'<td width="57%">'
funcion(document.rbb.titulo.value)
if (output!="")
	{
		document.rbb.contenidoGenerado.value=document.rbb.contenidoGenerado.value+output+'</td>'
	}
	
+'\n'+'</tr>'
+'\n'+'<tr>'
+'\n'+'<td><strong>G&eacute;nero:</strong></td>'
+'\n'+'<td>'
funcion(document.rbb.genero.value)
if (output!="")
	{
		document.rbb.contenidoGenerado.value=document.rbb.contenidoGenerado.value+output+'</td>'
	}
+'\n'+'</tr>'
+'\n'+'<tr>'
+'\n'+'<td><strong>Pa&iacute;s:</strong></td>'
+'\n'+'<td>'
funcion(document.rbb.pais.value)
if (output!="")
	{
		document.rbb.contenidoGenerado.value=document.rbb.contenidoGenerado.value+output+'</td>'
	}
+'\n'+'</tr>'
+'\n'+'<tr>'
+'\n'+'<td><strong>A&ntilde;o:</strong></td>'
+'\n'+'<td>'
funcion(document.rbb.ano.value)
if (output!="")
	{
		document.rbb.contenidoGenerado.value=document.rbb.contenidoGenerado.value+output+'</td>'
	}
+'\n'+'</tr>'
+'\n'+'<tr>'
+'\n'+'<td><strong>Duraci&oacute;n:</strong></td>'
+'\n'+'<td>'
funcion(document.rbb.duracion.value)
if (output!="")
	{
		document.rbb.contenidoGenerado.value=document.rbb.contenidoGenerado.value+output+'</td>'
	}
+'\n'+'</tr>'
+'\n'+'<tr>'
+'\n'+'<td><strong>Puntuación IMDB:</strong></td>'
+'\n'+'<td>'
funcion(document.rbb.puntuacion.value)
if (output!="")
	{
		document.rbb.contenidoGenerado.value=document.rbb.contenidoGenerado.value+output+'</td>'
	}
+'\n'+'</tr>'
+'\n'+'<tr>'
+'\n'+'<td valign="top"><strong>Sinopsis:</strong></td>'
+'\n'+'<td>'
funcion(document.rbb.sinopsis.value)
if (output!="")
	{
		document.rbb.contenidoGenerado.value=document.rbb.contenidoGenerado.value+output+'</td>'
	}
+'\n'+'</tr>'
+'\n'+'</table>'
+'\n'+'<br><br>'

document.rbb.contenidoGenerado.focus()
	}
EL caso es que me comienza a printar por pantalla pero hay muchos caracteres que no los imprime. Les dejo aquí lo que me saca por pantalla:

Código:
<table align="center" width="90%"  border="1">
<tr>
<td width="28%" rowspan="7"><div align="center">
<a href="http://www.dalotodoymas.com/index.php?option=com_wrapper&Itemid=8" target="_blank"><img src="http://www.dalotodoymas.com/index.php?option=com_wrapper" width="120" height="180" border="2" title="silent hill"></img></a></div></td>silent hill</td>terror</td>españa</td>2006</td>120 minutos</td>6.6/10 (16,420 votos)</td>Rose no puede aceptar que su hija Sharon está muriendo a causa de una terrible enfermedad. Pese a las protestas de su marido, ella huye con su hija con la intención de llevarla a un sanador. En el camino, llega a una ciudad misteriora y desierta, Silent Hill. Sharon desaparece allí y Rose sigue a través de la ciudad lo que piensa que es la silueta de su hija. Silent Hill no es un lugar cualquiera. Está habitado por extrañas criaturas y por una oscuridad que transforma todo lo que toca. Los pocos habitantes que quedan, están atrapados en una lucha perdida contra la oscuridad. Allí Rose conocerá a una mujer policía, Cybil, que tratará de ayudarla.</td>
A ver si alguien me puede hechar una mano,

Saludos y gracias
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:48.