Reputation: 455
<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>
Upvotes: 0
Views: 70
Reputation: 993
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();
}
Upvotes: 1
Reputation: 11
You can use Ajax to create asynchronous Web applications. Ajax can send data and retrieve from a server, e.g., RESTful API.
If you want to show Page1 and hide Page2.
$("#Page1").show();
$("#Page2").hide();
References.
Upvotes: 1