On a website I remeber seeing a news feature where the news would be a bar with a title and you clicked it and it would expand showing the message and other information and the code used was javascript:show but I don't understand how it works (as the news was got from a mysql database) how would this be done?

I want to now how to code something like that so i can make expanding stuff.

You do just what you said: have server-side code perform a query or stored procedure, render the results in a DIV, and toggle the visibility of that div using JavaScript.

Again, which part do you have a question about?

So it would be?

<a href="javascript:show('news1');">Welcome</a><br>
<div id="news1">
welcome to the site
</div>

You said the result should be rendered in a Div, what I replace the "Div" with a "tr" tag?

So it would be?

<a href="javascript:show('news1');">Welcome</a><br>
<div id="news1">
welcome to the site
</div>

That would be the HTML part of it, yes.

Then, you'll need CSS assigned to the DIV in order to make it initially invisible.

You'll need to write a JavaScript function named "show", which accepts the ID of the div and changes the style to "visible".

You'll need the server-side code to retrieve "welcome to the site" from a database and write the above output.

You said the result should be rendered in a Div, what I replace the "Div" with a "tr" tag?

Then you would get a badly broken HTML fragment. You really don't want elements that will have their display and/or visibility properties dynamically changed, within a table.

This article has been dead for over six months. Start a new discussion instead.