1
The function creates inputs for data inclusion
By clicking add, the fields are generated correctly
The problem is that it always sends the number 1:
a) If you just open and click Send;
b) and even typing texts.
what sends:
campo1 = 1
campo2 = 1
field 3 = 1
...
How to send the entered data in the open fields?
thanks in advance
var qtdeCampos = 0;
function addCampos() {
var objPai = document.getElementById("campoPai");
var objFilho = document.createElement("div");
objFilho.setAttribute("id","filho"+qtdeCampos);
objPai.appendChild(objFilho);
document.getElementById("filho"+qtdeCampos).innerHTML = "<input type='text' id='campo"+qtdeCampos+"' name='campo"+qtdeCampos+"' value=''>";
qtdeCampos++;
}
<!doctype html><html lang="pt-br">
<head><meta charset="UTF-8">
</head><body>
<form name="gru" method="post" action="grava.php">
<div id="campoPai"></div>
<input type="button" value="adicionar" onclick="addCampos()">
<hr><input type="submit" value="Enviar">
</form>
</body></html>
Why do you use me
id
does not useclass
? Still avoids having to create oneid
for each field. It doesn’t make much sense to create severalid
s sequential if with a class you solve much more easily.– Sam
Can you put an example? thank you
– Geo
Yes, I can put an example. But, as you are getting the fields in PHP?
– Sam
only receives the 1 of qq field. (if send in blank or typed). The function Is not sending the typed text.
– Geo
in grava.php receives: if(isset($_POST) AND Empty($_POST['campo0'])||Empty($_POST['campo1']): echo'campo 0 = '.isset($_POST['campo0']); echo'campo 1 = '.isset($_POST['campo1']); endif;
– Geo