nuisance nuisance - 1 year ago 47
HTML Question

How to update my html when the DB returns a value ?

function show(shown, hidden) {
return false;


<div id="Page1">
Content of page 1
<a href="#" onclick="return show('Page2','Page1');">Show page 2</a>

<div id="Page2" style="display:none">
Content of page 2
<a href="#" onclick="return show('Page1','Page2');">Show page 1</a>


In this code you see that
<a href="#" onclick="return show('Page2','Page1');">Show page 2</a>

this code jump to page 2.

This code works fine but I need to do a little diffrent.When my db returns a value like 3,I want to jump the third page or if my db returns value of 2 I want to jump the second page. So my main problem is how can I take the return value and use it in this code ?

<a href="#" onclick="return show('valueofreturn','Page1');">Show page return value</a>

Answer Source

use a JSON call to retrieve the data from your server, then in the success handler, hide all pages and then show the one you want :

$.getJSON( "ajax/test.json", function( data ) {
    $('#page' + data.pageid ).show();