StefanRSA Posted November 25, 2009 Share Posted November 25, 2009 I have a while loop in php that creates [*]The js lookup with field id's [*]The different Div id's with links When I click on any link in its own div, only the last div in the loop gets updated??????? And I did check to see that its got a different div id.......? My form with the loop: while($row2 = mysql_fetch_array( $query1 )) { $field_id = $row2['id']; ?> <script type="text/javascript" src="<?=$root;?>/member/incl/keyfieldjs.php?field_id=<?=$field_id?>"> </script> <? echo '<div id="'.$field_id.'"><a href="#" onClick=\'check_content'.$field_id.'("'.$root.'/member/keyfield.php")\'><img src="'.$root.'/header/images/but_report.gif" border="0"> </a></div>'; } The keyfieldjs.php: <?PHP $field_id = $_GET['field_id']; ?> function makeObject(){ var x; if (window.ActiveXObject) { x = new ActiveXObject("Microsoft.XMLHTTP"); }else if (window.XMLHttpRequest) { x = new XMLHttpRequest(); } return x; } var request = makeObject(); var the_content; function check_content<?=$field_id?>(the_content){ request.open('get', the_content); request.onreadystatechange = parseCheck_content; request.send(''); } function parseCheck_content(){ if(request.readyState == 1){ document.getElementById('<?=$field_id?>').innerHTML = 'Loading...'; } if(request.readyState == 4){ var answer = request.responseText; document.getElementById('<?=$field_id?>').innerHTML = answer; } } And lastly.... The keyfield.php <?PHP echo 'Field Marked as Key!'; ?> Link to comment https://forums.phpfreaks.com/topic/182897-funny-ajax-behaviour-with-while-loop-in-php/ Share on other sites More sharing options...
trq Posted November 25, 2009 Share Posted November 25, 2009 Cool. Link to comment https://forums.phpfreaks.com/topic/182897-funny-ajax-behaviour-with-while-loop-in-php/#findComment-965361 Share on other sites More sharing options...
StefanRSA Posted November 25, 2009 Author Share Posted November 25, 2009 Sorry Thorpe... I wanted to previed the post and clicked on submit before it was complete.... Hope its clear now that is complete Link to comment https://forums.phpfreaks.com/topic/182897-funny-ajax-behaviour-with-while-loop-in-php/#findComment-965376 Share on other sites More sharing options...
StefanRSA Posted November 25, 2009 Author Share Posted November 25, 2009 I Have now changed my keyfieldjs.php to: <?PHP $field_id = $_GET['field_id']; ?> function makeObject<?=$field_id?>(){ var x; if (window.ActiveXObject) { x = new ActiveXObject("Microsoft.XMLHTTP"); }else if (window.XMLHttpRequest) { x = new XMLHttpRequest(); } return x; } var request = makeObject<?=$field_id?>(); var the_content<?=$field_id?>; function check_content<?=$field_id?>(the_content<?=$field_id?>){ request.open('get', the_content<?=$field_id?>); request.onreadystatechange = parseCheck_content<?=$field_id?>; request.send(''); } function parseCheck_content<?=$field_id?>(){ if(request.readyState == 1){ document.getElementById('<?=$field_id?>').innerHTML = 'Loading...'; } if(request.readyState == 4){ var answer = request.responseText; document.getElementById('<?=$field_id?>').innerHTML = answer; } } Now, it is updating the link clicked but if I click on any other link in the loop, the previous link clicked change its status to: loading... Anybody clever enough to help me.... PLEASE Link to comment https://forums.phpfreaks.com/topic/182897-funny-ajax-behaviour-with-while-loop-in-php/#findComment-965383 Share on other sites More sharing options...
StefanRSA Posted November 25, 2009 Author Share Posted November 25, 2009 I was playing around with the code in the JS file.... I dont know why.... But changing : document.getElementById('<?=$field_id?>').innerHTML = 'Loading...'; to document<?=$field_id?>.getElementById('<?=$field_id?>').innerHTML = 'Loading...'; WORKS!!! Link to comment https://forums.phpfreaks.com/topic/182897-funny-ajax-behaviour-with-while-loop-in-php/#findComment-965402 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.