Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 591023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:35:29+00:00 2026-05-13T15:35:29+00:00

I am trying to create an auto-refresh for a table using ajax/jquery, php/html, and

  • 0

I am trying to create an auto-refresh for a table using ajax/jquery, php/html, and Drupal 6.

Code once the database insert has finished and was successful:

echo "<script type='text/javascript'>autoRefresh()</script>";

Code for the link that eventually calls the javascript code that actually performs the refresh of the table:

    $block_content .= "<br><a id='refreshItemId' class='refreshItemLink' href='$host_url/refresh/projectitems/gid/$curr_gid/nid/$curr_nid'>Refresh List</a>";

Javascript code that is added to the page using PHP (I know it could be a javascript file and then include that, but that’s for another day). This is the code I added to attempt to automatically make click() the link created above once a form is submitted and the item was successfully added to the database:

    $block_content .= "<script type='text/javascript'>
        function autoRefresh()
        {
            alert('Auto Refresh');
            //document.getElementById('refreshItemId').click();
        }
    </script>";

I thought this would have worked, but the autoRefresh() JS function never gets called. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:35:29+00:00Added an answer on May 13, 2026 at 3:35 pm

    You need to wrap the AutoRefresh call in a “onload” event handler. Right now the function is running (or trying to run) as soon as it is output to the browser, so there isn’t a button to click at that point.

    In jquery:

    <script type="text/javascrpt">
        $(function() {
            autoRefresh();
       });
    </script>
    

    Update:

    If you want the refresh button to be clicked after the user has made changes via AJAX, do something like:

    $.ajax({
      data: //data sent to script;
      url: //path to PHP script
      success: autoRefresh();
      }
    });
    

    If you want to only have it update when the PHP script sends some kind of “safe word” change the success function to something that reviews the server’s response, and if it’s the “all clear” signal, then does the autoRefresh.

    Update 2:

    Okay, having hashed this out, what you need is your own event handler tied to the function. So have the PHP output the following jquery script:

     <script type="text/javascript">
    
     $(function() {
         $("#refreshItemId").click(function() {
         $(this).delay('200');
         autoRefresh();
         });
     });
    

    Couple of notes:

    The delay method is new to jquery 1.4. If you have an older version, there are other methods that can be used to stall the function.

    I haven’t had a chance to mess with .delay() that much yet, so I may have messed up a bit.

    But the overall idea should be clear: Bind the function to the link when the page loads; When the onclick event triggers the function, it waits .2 seconds for the Drupal ajax to finish; finally, it triggers the autoRefresh function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an auto-updating app using Winforms. I can't use click-once or
I trying to create a auto-complete search script (jQuery + PHP) but I have
I am trying to create a simple ajax chat using JQuery and ASP.NET. My
I am trying to create auto-vectorized code with clang-3.2 From the slides here -
I'm trying to create a table that has a primary key (Department_ID) that auto
So I'm trying to create a federated table using the syntax from the docs
Essentially I'm trying to create the HTML/CSS for an auto-complete. I want it to
I am trying to create this table in my php file: mysql_query(CREATE TABLE Orders
I have been trying to create rotating object using jQuery and without any other
I'm trying to create a good match query for an auto-complete search box using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.