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 7438093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:30:05+00:00 2026-05-29T10:30:05+00:00

I have written the following jQuery for autorefreshing a page containing a poll (to

  • 0

I have written the following jQuery for autorefreshing a page containing a poll (to keep updating the current winning option)

function update() {
  var vote_radio = $('input:radio[name=vote_radio]:checked').val();
  $.ajax({
    type: 'POST',
    url: 'index.php',
    data: 'refresh=true&maintain_radio='+ vote_radio,
    timeout: 2000,
    success: function(data) {
      $("#current_body").html(data);
      $("#notice_div").html(''); 
      $("[name=vote_radio]").filter("[value="+vote_radio+"]").attr("checked","checked");
      window.setTimeout(update, 2000);
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
      $("#notice_div").html('Timeout contacting server..');
      window.setTimeout(update, 60000);
    }
});
};

$(document).ready(update);

There is a radiobutton poll on the page named “vote_radio”, I also use the following code with that, to Ajax the answers to the server:

    $(function() {  
  $('.error').hide();
  $('.failure').hide();
  $('.success').hide();
  $(".vote_submit").click(function() {
        if (!$("input[@name='name']:checked").val()) {
            $('.error').show();
            return false;
        }
        var vote_radio = $('input:radio[name=vote_radio]:checked').val();;
        var dataString = 'vote_radio='+ vote_radio;
        $.ajax({
          type: "POST",
          url: "index.php",
          data: dataString,
          success: function() {
            $('.success').show();               
            $('.failure').hide();               
          },
          error: function() {
            $('.failure').show();               
            $('.success').hide();               
          }
        });
        return false;
  });
});

The problem I’m having with all this is that if a user selects their option WHILE the page is auto-refreshing it puts the selected radio option back to how it was WHEN the page started auto-refreshing, which is frustrating.

Also, if the .success class has been told to appear by the second script, when the first script autorefreshes the page it hides the success class again.

  • 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-29T10:30:06+00:00Added an answer on May 29, 2026 at 10:30 am

    Why are you reverting the vote_radio element back to the value before initiating the AJAX call ?

    Just read it right before overwriting it, so you keep the current value (even if it changed without being submitted yet)

    so just change the success callback to

    success: function(data) {
          var vote_radio = $('input:radio[name=vote_radio]:checked').val();
          $("#current_body").html(data);
          $("#notice_div").empty(); 
          $("[name=vote_radio]").filter("[value="+vote_radio+"]").attr("checked","checked");
          window.setTimeout(update, 2000);
        }
    

    But, in general, the correct way would be to update only the parts of the page that need updating, and not the whole page.. that is the whole point of AJAX..

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

Sidebar

Related Questions

I have written a plugin with the following signature: jQuery.fn.attach = function(element, settings, duration,
I have written a small jQuery plugin with the following structure: (function($) { //
I have written the following algorithm in order to evaluate a function in MatLab
I am fairly new to jQuery and have written the following code to show
Possible Duplicate: jquery ajax return: undefined I have written the following code to check
I am still new to Javascript and JQuery. I have written a small function
I have the following code, written using jQuery: var strval = '22' $(#quicknote).attr(href, javascript:location.href=/'http://site.com/notes/add?projects=/'+
I have written the following jquery code block. When a postcode is changed on
If you look at http://www.danfarrellwright.com/screwsline/front_end/product.php?product_id=104 I have written the following function to add the
I'm a jQuery novice, I have the following jQuery written to show a div

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.