Jump to content

Recommended Posts

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!';
?>

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

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!!!

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.