dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Auto refresh a span tag with id

  1. #1
    Join Date
    Feb 2013
    Posts
    4

    Auto refresh a span tag with id

    This is the tag I have been trying to auto-refresh //osCommerce tag FYI
    <span id="cartInfo"></span>

    with this script imbedded within the page that call the header file which ownes that tag
    <script>
    $(document).ready(function() {
    setInterval(function(){
    $("#cartInfo")
    }, 3000);
    $.ajaxSetup({ cache: false });
    });
    </script>


    I dont need to populate the tag with outside pge data just need it to re-populate itself with information stored in the database.

  2. #2
    Join Date
    Feb 2013
    Posts
    4
    <script type="text/javascript">
    function cartRefresh(){
    var t = document.getElementById('cartInfo');
    var r = parseInt(t.innerHTML);
    t.innerHTML = r;
    }
    x = setInterval(function (){ cartRefresh(); }, 3000);
    </script>


    Im getting closer!!! but now instead of a value '1 Items | $4.80" after 3 seconds the refresh is only returning the value '1'

  3. #3
    Join Date
    Feb 2013
    Posts
    4
    <script type="text/javascript">
    function cartRefresh(){
    var t = document.getElementById('cartInfo');
    var r = t.innerHTML;
    var items = "<?php echo $cart->count_contents() ?> items";
    var total = "<?php echo $cart->show_total() ?>";
    t.innerHTML = items + " | " + "$" + parseFloat(total).toFixed(2) + "---";
    }
    setInterval(function(){ cartRefresh(); }, 3000);
    </script>

    This is working!!! but only once any indeas why it will not loop evey three seconds

  4. #4
    Join Date
    Feb 2013
    Posts
    4
    SOLVED!!!! Yay I was way off

    $(document).ready(function() {

    function cartRefresh(){
    var params = {
    action: "getCartInfo"
    };
    $.ajax({
    type: 'POST',
    url: 'ajax.php',
    data: params,
    dataType: "html",
    success: function(result) {
    $('#cartInfo').html(result);
    }
    });
    }

    setInterval(function(){ cartRefresh(); }, 3500);

    });

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles