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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:32:18+00:00 2026-05-28T06:32:18+00:00

I have a jQuery vote script that allows a user to vote on a

  • 0

I have a jQuery vote script that allows a user to vote on a poll that is displayed on a page. On a particular page there are many polls being displayed (via forms) and the jQuery grabs the values of the inputs in a particular form and send the data over to a query.php page.

This is what a sample poll page looks like:

QUESTION 1:<br />
<div class="poll_area">
    <div id="poll">    
        <form method="POST" action="" class="poll_query">
            <input type="hidden" value="favorites" name="page" />
            <input type="hidden" value="user1" name="to" />
            <input type="hidden" name="pid" value="1"/>                            
            <input name="" type="radio" value="yes" /> Yes<br />
            <input name="" type="radio" value="no" /> No<br />                        
        </form>    
    </div>
    <div class="result"> </div>
</div>

QUESTION 2:<br />
<div class="poll_area">
    <div id="poll">    
        <form method="POST" action="" class="poll_query">
            <input type="hidden" value="favorites" name="page" />
            <input type="hidden" value="user2" name="to" />
            <input type="hidden" name="pid" value="2"/>                            
            <input name="" type="radio" value="yes" /> Yes<br />
            <input name="" type="radio" value="no" /> No<br />                        
        </form>    
    </div>
    <div class="result"> </div>
</div>

And this is the jQuery Script I’m running:

var ajax_load = "<img src='images/ajax-loader.gif' alt='loading...' />";
$("form.poll_query > input[type='radio']").click(function(e) {
    e.preventDefault();
    var form= $(this).closest("form");
    var pid = $("input[name='pid']", form).val();
    var ans = $(this).val();
    var page = $("input[name='page']", form).val();
    var to = $("input[name='to']", form).val();

    $(this).closest("#poll").html(ajax_load);
    $.post(
        "query.php?module=vote",  
        {answer: ans, pid: pid, to: to, page: page},
        function(responseText){  
            $("#poll").hide(0,function() {
                $(".result").html(responseText).fadeIn(1500);
            }); 
        },  
        "html"
    );
});

When voting in the first poll everything renders correctly. The ‘responseText’ that is returned is displayed in the page where it is supposed to. But for every subsequent poll on the page the ‘ajax_load’ loads correctly where it is supposed to but the ‘responseText’ is loaded in the .result class of the FIRST poll.

This is what the page initially looks like:

Question 1? 
o YES 
o NO

Question 2?
o YES 
o NO

if a particular user votes on question 2 this is what the page should look like:

Question 1? 
o YES 
o NO

Question 2 
o YES : XXXXXXXXX 60%
o NO  :  XXXXXX 40%

Instead this is what actually happens (even though the user voted on question 2):

Question 1? 
o YES : XXXXXXXXX 60%
o NO  : XXXXXX 40%

Question 2 
o YES 
o NO

But if the user votes on question 1 the results is loaded properly:

Question 1? 
o YES : XXXXXXXXX 60%
o NO  : XXXXXX 40%

Question 2 
o YES 
o NO

I’ve tried changing $(".result").html(responseText).fadeIn(1500); to $(this).closest(".result").html(responseText).fadeIn(1500);

But still no luck.

  • 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-28T06:32:18+00:00Added an answer on May 28, 2026 at 6:32 am

    You have duplicate element IDs for poll. You should use a class instead, then make your selectors in the callback more precise. You’re on the right track with $(this).closest().

    You’ll need to do something like:

    var pollArea = $(this).closest(".poll_area");
    $.post(... , function(responseText) { 
      pollArea.find(".poll").hide(0,function() {
          pollArea.find(".result").html(responseText).fadeIn(1500);
    }); 
    

    Note that the .poll and .result selectors are now scoped by the .poll_area that encloses the clicked radio button.

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

Sidebar

Related Questions

i have this jquery voting script, everything is working fine, it just that the
I have jquery code that is being reused by a repeatable partial view on
I have written the following jQuery for autorefreshing a page containing a poll (to
I have jQuery to select all font elements that are children of the element
does jquery have any plugin that prevents entering any input to a textbox that
I have a jquery variable that isnt working and it's most likeley because i
I have some jquery variables that attempt to get values of nearby elements however
I have this css code that shows the photos twice, its weird, is there
I have a script that creates a list of items with a structure like
I'm implementing a vote system and I want to use jQuery. I have the

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.