PDA

View Full Version : Thickbox & JS Query



hfidgen
11-26-2008, 02:33 PM
Hi,

I'm trying to set up a list of <a hrefs> which when clicked pull content from a SQL database and display it in a specific <div> on the page. This works, it's all fine. What I'd like to do though is have the returned content pop up in a thickbox.

And this is where I'm stuck! Javascript is not my forte, although i'm happy enough to play around with it and I can't work out the process this needs.

The code I have breaks down to this (much simplified)

The A hrefs are constructed like this: "name" is the ID number of the content in the database.

<a href="#" onclick="getnews(this.name);" name="1">Title Here</a>

The getnews() function looks like this - q is appended to the string passed over to "getnews.php" which then takes q and uses it to fetch the relevant row from the database, returning the title and text of the content page in question.

function getnews(str)
{
xmlHttp=GetXmlHttpObject()
var url="getnews.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

And the function which returns the content to the main page is this:

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("news_content").innerHTML=xmlHttp.responseText
}
}

So you see, this is all pretty simple - a href contains the ID number of the article, the getnews() function takes that ID to getnews.php which accesses the DB, formats the response and passes it onto statechanged() which then takes the content back to the page and inserts it into <div id="news_content"></div>

Now... how on earth to get the content which is bieng passed back to display in a thickbox?! I literally have no idea at the moment, I'm playing around but the best I can do is get the thickbox loading bar up with no content in there..

All help appreciated :D
Thanks