最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Refresh a Div, Table or TR without reloading page and without using Ajax - Stack Overflow

programmeradmin4浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 3

Yes, 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.

发布评论

评论列表(0)

  1. 暂无评论