Jump to content

include var in getElementbyID


MikeDXUNL

Recommended Posts

var xmlHttp

function readmore(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="ajax/findnews.php";
url=url+"?newsid="+str;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("full").innerHTML=xmlHttp.responseText;  
}
}

 

 

i tried:

("full"+str)

("full"+str"")

 

and I cant seem that line to equal

 

full plus the str

 

help please?

 

Thanks,

Mike

Link to comment
https://forums.phpfreaks.com/topic/89019-include-var-in-getelementbyid/
Share on other sites

in my html I have a line saying:

 

<div id="full<?php echo $news['newsid']; ?>"> </div>

 

say $news['newsid'] is 15

 

there is a link called Read More:

 

<div id="readmore<?php echo $news['newsid'];?>"><a href="#" onClick="readmore('<?php echo $news['newsid']; ?>'); return false;">Read More</a></div>

 

 

When they click Read More, It access the function and grabs Info from a PHP file.

Then whatever is returned, should be placed in

 

<div id="full<?php echo $news['newsid']; ?>"> </div>

 

but I can't figure out in the JS:

document.getElementById("full").innerHTML=xmlHttp.responseText; 

 

how to make full+str work so it will say "getElementByID("full15") technically

 

 

You need to set the entire id with a parameter and then this will work.

 

Example:

 

<script language="javascript">
function readmore(from)
{
document.getElementById(from).innerHTML = xmlHttp.responseText;
}
</script>

<div id="readmore<?php echo $news['newsid'];?>"><a href="#" onClick="readmore('<?php echo $news['newsid']; ?>'); return false;">Read More</a></div>

 

Do something to this extent and I think it will work the way you want it to. ;)

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.