Refresh Div, Table or TR without reloading the page and without using Ajax

Is it possible to update a div, table or <tr> . Here, such data does not come from the database, its simple error display unit and value comes from a Java script.

The problem is that when the user enters a value in a text field, the value stored in this database and the successfully saved message appears on the screen.

Then again on the same page the user tries to enter the wrong value, then an error is displayed in this block, but the previous value remains, i.e. "Successfully saved message."

Sentence

+4
source share
2 answers

Yes, you can easily clear an element of its children (that is, a success message) when an event occurs. In your case, the event will enter data in the text box. Assuming the following markup:

 <input type="text" id="textbox" name="textbox"/> <div id="message"> Successfully Stored Message </div> 

When you detect another event in your text box, you simply clear the <div id="message"> as follows:

 var textbox = document.getElementById('textbox'); textbox.onchange = function(){ // Do some test to determine if you should clear #message // Get your #message container and remove all its children var message = document.getElementById('message'); while(message.hasChildNodes()){ message.removeChild(message.firstChild); } }; 

Change the input value in this example to see it in action.

+3
source

So, looking around the world, I found an easy way to do a “fix”:

  <script> $(document).ready(function() { $("#refresh").click(function() { $("#Container").load("content-that-needs-to-refresh.php"); return false; }); }); </script> <div id="Container"> <?php include('content-that-needs-to-refresh.php'); ?> </div> <a href="#" id="refresh">Refresh</a> 

in file: content-that-needs-to-refresh.php

You put everything you want to update / Updated / Changed.

File Content: content-that-needs-to-refresh.php

  <?php $random = rand(1, 10); $numbers[1] = "1"; $numbers[2] = "2"; $numbers[3] = "3"; $numbers[4] = "4"; $numbers[5] = "5"; $numbers[6] = "6"; $numbers[7] = "7"; $numbers[8] = "8"; $numbers[9] = "9"; $numbers[10] = "10"; ?> <?=$numbers[$random]?> 

This will give you a random number every time you click the refresh link.

+3
source

All Articles