nuisance nuisance - 3 months ago 5
HTML Question

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

<script>
function show(shown, hidden) {
document.getElementById(shown).style.display='block';
document.getElementById(hidden).style.display='none';
return false;
}
</script>

<body>

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

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

</body>


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

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').hide();
    $('#page' + data.pageid ).show();
}