Jump to content

function form for loop


Xillar

Recommended Posts

Hello,

( I'm dutch so my englisch is poor sorry :'( )

I've got a Ajax script with a for loop.
I want to make a new request from inside the for loop with a created onclick

as result i get this

id 1
id 2
id 3

i give this id with my onlick as you can see in my code below.
but if i click on the link in my result table te output in the next function handle_fact is always 3.

my code:

for loop:
[code]
for ( i=0;i<results.length; i++){
         
          var artId = result.getElementsByTagName("artId");
          var artId = artId.item(i);
          var artId = artId.firstChild.nodeValue
         
          var artTr = document.createElement("tr");
         
          var artaddTd = document.createElement("td");
          artaddTd.className = "addTd";
          artaddTd.innerHTML = artId;
         
          artaddTd.onclick = function()
          {
              make_request('mandje.php?id=' + artId, 'handle_fact', 'GET', null, true);
          }
         
          artTr.appendChild(artaddTd);
          artTbody.appendChild(artTr);
          artTable.appendChild(artTbody);
          artDiv.appendChild(artTable);
          suggestionDiv.appendChild(artTable);
       
        }
[/code]

result code handle_fact:
[code]
function handle_fact(result) {
    var productenDiv = document.getElementById("productenDiv");
     
    var results = result.getElementsByTagName('result');
    productenDiv.innerHTML = '';
     
    for( ii=0; ii<results.length; ii++) {
    var test= result.getElementsByTagName("test");
    var test = test.item(ii);
      productenDiv.innerHTML = test.firstChild.nodeValue;
    }
    }
[/code]
Link to comment
https://forums.phpfreaks.com/topic/34871-function-form-for-loop/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.