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

 

Link to comment
Share on other sites

 

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. ;)

Link to comment
Share on other sites

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.