Ver Mensaje Individual
  #6 (permalink)  
Antiguo 21/06/2008, 18:25
anion0x
 
Fecha de Ingreso: junio-2008
Mensajes: 110
Antigüedad: 15 años, 11 meses
Puntos: 0
Respuesta: agregar input a un form

Con los ejemplos que encontre pude llegar a a hacer esto, pero no lo puedo terminar.

Cita:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Test jQuery</title>

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.highlightFade.js"></script>

<script type="text/javascript">
function addFormField() {
var id = document.getElementById("idioma").value;
$("#divTxt").append("<p id='row" + id + "'><label for='txt" + id + "'>Idioma &nbsp;<input type='text' size='20' name='txt[]' id='txt" + id + "'>&nbsp;&nbsp<a href='#' onClick='removeFormField(\"#row" + id + "\"); return false;'>Quitar</a><p>");

id = (id - 1) + 2;
document.getElementById("id").value = id;
}

function removeFormField(id) {
$(id).remove();
}
</script>

<body>


<form action="#" method="get" id="form1">

<div id="divTxt">
<tr id="fiel">
<th><label for="idiomas">Idioma</label></th>
<td><input type="text" name="idiomas" id="idioma" value="" /></td>
<th><label for="domIdioma">% de dominio</label></th>
<td><input class="short" type="text" name="domIdioma" id="domidioma" value="" />
</tr>
</div>
<p><a href="#" onClick="addFormField(); return false;">[+] Agregar</a></p>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>
</form>

</body>
</html>
Lo que necesitaria es que se agregue esto cuando hago click.

Cita:
<tr id="fiel">
<th><label for="idiomas">Idioma</label></th>
<td><input type="text" name="idiomas" id="idioma" value="" /></td>
<th><label for="domIdioma">% de dominio</label></th>
<td><input class="short" type="text" name="domIdioma" id="domidioma" value="" />
</tr>
Alguna idea?

PD: faltan algunos tags de table, por ej, pero creo que para ejemplo no hacen falta.