There is a form in which the fields are loaded via Ajax . Each field is assigned an id , for example, birthdayosoba_0 , birthdayosoba_1 , etc. There is also a field with the number of fields I need to add. In the script itself, I pull out the number of fields and assign a value to a variable. Then, in a cycle, I assign dynamic values ​​to dynamic variables. And then I need to throw the values ​​obtained on the handler via Ajax .

Js code:

 function osoby_calc2() { var kil_osoby = document.getElementById('kil_osoby').value; for (var i = 0; i < kil_osoby; i++) { window['point_' + i] = document.getElementById("birthdayosoba_" + i).value; alert(point_0); //чисто для проверки работоспособности } $("#osoby_calc3").load("osoby_calc.php", { kil_osoby : kil_osoby }); } 

When cleaning:

 for (var i = 0; i < kil_osoby; i++) { window['point_' + i] = document.getElementById("birthdayosoba_" + i).value; alert(point_0); //чисто для проверки работоспособности } 

then the data is normally transferred to the handler. But if part of the code is present, then alert() works, but the data does not go away.

Where am I wrong? PS: I will ask you not to give advice on arrays, etc. There is no possibility to use them, you need to correct this example. Thank you in advance.

  • Check for all i have document.getElementById("birthdayosoba_" + i).value ? - Rolandius
  • I figured it out, but now the problem of a larger nature arose ((( - Alexander
  • What was the problem? What is wrong now? - Rolandius
  • The problem was that when I wrote the script for the test, I manually hammered the number of cycles, but in reality there were fewer fields, which is why it did not work. ) .load ("osoby.php", {kil_osoby: kil_osoby}); ' it passes various parameters. Here's how I put new variables with their dynamic values ​​in parameter passing! - Alexander

1 answer 1

alert does not work inside the function - gives the last value, use a closed expression.

  • Alert works normally. Message is displayed. The problem is that $("#osoby_calc3").load("osoby_calc.php", { kil_osoby : kil_osoby }); does not work. I need an alert only to see that the data is being transmitted. It can be removed at all - Alexander
  • It seems to me that you are wrong. Denial of . I think you meant that the alert suspends the execution of the script. - Rolandius
  • I deleted it but the process has not changed. I just sat there and realized that even such an architecture would not help even if I deal with the problem. The fact is that I need to pass all the generated data to the handler. And I think that I can't do without arrays no matter how much I want it - Alexander
  • @ Alexander, what is the problem of arrays? - Rolandius
  • @Rolandius, it's funny that inside the alert function it works, it was not noticed before. without a function - alert does not work jsfiddle.net/xngv8qgu/1 - Deus