Nuisance
Nuisance

Reputation: 455

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>

Upvotes: 0

Views: 70

Answers (2)

Rich Linnell
Rich Linnell

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

blackcl
blackcl

Reputation: 11

  1. Get data from server side.

You can use Ajax to create asynchronous Web applications. Ajax can send data and retrieve from a server, e.g., RESTful API.

  1. show/hide "div"

If you want to show Page1 and hide Page2.

 $("#Page1").show(); 
 $("#Page2").hide();
  1. Java Server You can use JavaBeans / JSP to do this work.

References.

http://api.jquery.com/show/

http://api.jquery.com/jquery.ajax/

Upvotes: 1

Related Questions