Is it possible to refresh a div, table or <tr>
. Here no such data es from database, its a simple error displaying block and value es from Java-script.
Issue is that when an user inputs a value in textbox, value stored in that database and Successfully Stored Message es on the Screen.
Then again at the same page, user try to enter wrong value then error shows in that block, but the previous value remains ie "Successfully Stored Message".
An suggestion ???
Is it possible to refresh a div, table or <tr>
. Here no such data es from database, its a simple error displaying block and value es from Java-script.
Issue is that when an user inputs a value in textbox, value stored in that database and Successfully Stored Message es on the Screen.
Then again at the same page, user try to enter wrong value then error shows in that block, but the previous value remains ie "Successfully Stored Message".
An suggestion ???
Share Improve this question asked Sep 3, 2010 at 15:35 RahulOnRailsRahulOnRails 6,54210 gold badges54 silver badges87 bronze badges 1- Can you give source code, which shows "Successfully Stored Message"? Or provide a sample screenshot of it? – Ivan Nevostruev Commented Sep 3, 2010 at 15:42
2 Answers
Reset to default 3Yes, you can easily clear an element of it's children (i.e. a success message) when some event occurs. In your case, the event would be entering data in a textbox. Assuming the following markup:
<input type="text" id="textbox" name="textbox"/>
<div id="message">
Successfully Stored Message
</div>
When you detect another event on your textbox, you just empty 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's value in this example to see it in action.
So after looking all over the web for this i found a simple way to do "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 the file: content-that-needs-to-refresh.php
You put whatever you would like to have refreshed / Updated / Changed.
Contents of file: 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 the give you a random number each time you click on the "Refresh" link.