Tengo un formulario html. Cuando hace clic en el botón, una función de JavaScript agrega un nuevo campo. Estoy intentando que la función también agregue una 'etiqueta' para el campo también.creando un campo de entrada para la forma html ... pero agregando una 'etiqueta' para eso también?
He intentado usar document.createElement ("Etiqueta"), pero eso no me deja cambiar el innerHtml (o tal vez estoy haciendo mal ..), ni añadir un cierre
Aquí es mi código ¡Gracias! var instance = 2;
function newTextBox(element)
{
instance++;
// Create new input field
var newInput = document.createElement("INPUT");
newInput.id = "text" + instance;
newInput.name = "text" + instance;
newInput.type = "text";
instance++;
document.body.insertBefore(document.createElement("BR"), element);
document.body.insertBefore(newInput, element);
}
</script>
</head>
<body>
<LABEL for="text1">First name: </LABEL>
<input id="text1" type="text" name="text1">
<LABEL for="text2">Last name: </LABEL>
<input id="text2" type="text" name="text2">
<input type="button" id="btnAdd" value="New text box" onclick="newTextBox(this);" />
</body>
publicar su código donde ha intentado hacer un 'document.createElement ('etiqueta')' para poder depurarlo. – philfreo
lo siento, lo borré porque pensé que era inútil: \t \t \t \t var label = document.createElement ("LABEL"); \t \t \t \t label.htmlPara = newInput.id; \t \t \t \t label.value = 'Nombre'; – Matt
No existe tal cosa como 'label.value'. – bobince