admin管理员组文章数量:1327750
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.
本文标签:
版权声明:本文标题:javascript - Refresh a Div, Table or TR without reloading page and without using Ajax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742234370a2437800.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论