Question

I'm beginner in usign Ajax XMLHttpRequest, I've a few issues that I need to solve.

I've a form that reads information from MYSQL table. These information are displayed for the user using "while looping".

Each table row is displayed for the user as html form with two text-fields.

Ex: Row 1

<form id="form_excecoes11" method="post">
Text-field 1: <input name="ini_exp1" id="ini_exp1" type="text">
Text-field 2: <input name="ini_exp2" id="ini_exp2" type="text">
<input name="id_dia" id="id_dia" type="hidden" value="11" />

<img src="save.jpg" height="25" width="26" onclick="save();" id="botao_salvar">
</form>

Row 2

<form id="form_excecoes12" method="post">
Text-field 1: <input name="ini_exp1" id="ini_exp1" type="text">
Text-field 2: <input name="ini_exp2" id="ini_exp2" type="text">
<input name="id_dia" id="id_dia" type="hidden" value="12" />

<img src="save.jpg" height="25" width="26" onclick="save();" id="botao_salvar">
</form>

These text-field have their names assigned dynamically (using variable values).

After the user change the value from text-fields, he click in "save" button. This triggers an XMLHttpRequest from a JS external file.

What I need is that my JS reads all text-field name and value and send it with xmlhttp.send(params).

In the JS file I only get the variable values from ROW 1( I can see that I php echo result), I can't get the values from ROW 2.

Why?

function save(){
//...
     var js_ini_exp = document.getElementById("ini_exp");
  var js_ini_exp2 = encodeURIComponent(js_ini_exp.value);

     var js_ini_exp3 = document.getElementById("ini_exp2");
 var js_ini_exp4 = encodeURIComponent(js_ini_exp3.value);

     var js_id_dia = document.getElementById("id_dia");
 var js_id_dia2 = encodeURIComponent(js_id_dia.value);
}

Maybe the problem ins document.getElementById ?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top