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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:46:40+00:00 2026-05-25T00:46:40+00:00

I have a survey-type ‘form’. What the user votes on changes, but the input

  • 0

I have a survey-type ‘form’. What the user votes on changes, but the input stays the same. After they press submit, among other things, the new thing the user gets to vote on is to be loaded. If the submit button is pressed at a low frequency, my program works fine. However, if it is pressed too quickly, my program breaks. I am confused as to why that is, since I have played around with enabling/disabling the button at particular times in my code.

Here is an excerpt of my HTML:

<button id='submit-vote' disabled='disabled'>Submit</button>
<element class='change'><INPUT id='hidden_id' TYPE='hidden' name='id' value='<?php echo $id; ?>'/></element>

Here is script from my jquery (I don’t know if this matters, but this is all written in between </body> and </HTML> tags, and not in between the <head> and </head> tags.):

    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $("#submit-vote").attr("disabled", false).data('disabled', false);
    });

    function loadListing()
    {
        var id = $('input:hidden[name=id]').val();
        $.get("controller.php",{/* [relevant values]*/}, 
        function(data)
        {
            if(data.response == 'success')
            {
                //some code
                var newId = $("<INPUT id='hidden_id' TYPE='hidden' name='id' value='"+data.id+"'/>");
                $('#hidden_id').replaceWith(newId);
                return true;
            }
            else
            {
                //some code
                return false;
            }
        }, "json");
    }
    jQuery(function($){
        $("#submit-vote").click( 
            function(){ 
                if($(this).data('disabled') !== false )
                {
                    return;
                }
                else
                {
                    $(this).attr('disabled', true).data('disabled', true);
                    $.post('controller.php', {/*[relevant values]*/} , 
                    function(data)
                    {
                        if(data.response == 'success')
                        {
                            //code
                            loadListing();
                            $('#submit-vote').attr('disabled', false).data('disabled',false);
                            return true;
                        }
                        else
                        { 
                            //code
                            $('#submit-vote').attr('disabled', false).data('disabled',false)
                            return false; 
                        } 
                    }, "json"); 
                }
            }
        );
    });
    </script>

EDIT: (I have updated my jquery to include code from the 1st answer to this question, and I have also included a bit more of my html).

Here is my ‘controller.php’ excerpt. I have edited a lot of stuff out of it, so as only to include the important stuff. The important thing to know is that all of this usually works perfectly fine unless the submit button click is clicked very very frequently.:

if(!isset($_POST['poll']) && !isset($_GET['newListing'])) //UPON PAGE LOAD
{
    $activities = Activity::newActivitiesArrays($user_id);
    $_SESSION['activities'] = $activities;
    //more relevant code
    include('view.php');
}
if(isset($_POST['poll']) && !isset($_GET['newListing'])) //submitting vote
{   
    //relevant code using posted values
    $res = Activity::vote($user_id, $id, $vote);
    if( !$res )
    {
        echo json_encode(array("response"=>"fail"));
    }
    else
    {
        echo json_encode( array("response"=>"success"));
    }
}
if(isset($_GET['newListing']) && isset($_GET['id'])) //getting something different to display
{
    $id = $_GET['id'];
    $activities = $_SESSION['activities'];
    list($acts, $links, $ids) = $activities;
    $keys = array_keys($ids, $id);
    $key=$keys[0];
    if(!$key)
    {
        echo json_encode( array("response"=>"failure"));
    }
    else
    {
        //relevant code
        unset($_SESSION['activities']);
        $_SESSION['activities'] = $activities;
        echo json_encode( array("response"=>"success"));
    }
}

Any help/suggestions appreciated.

  • 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-25T00:46:41+00:00Added an answer on May 25, 2026 at 12:46 am

    A button with the property disabled="disabled" will still fire a click event. You need to assign a variable so the script knows that it is disabled. I recommend using data()

            $(function(){
                 //The button should be enabled only as soon as the page is ready.
                $("#submit-vote").attr("disabled", false).data("disabled", false);
    
                $("#submit-vote").click( 
                    function(){ 
                        if($(this).data('disabled') !== false)
                        {
                            return;
                        }
                        else
                        {
                            $(this).attr('disabled', true).data('disabled',true); //disable the button
    
                            $.post('controller.php', {/* [RELAVANT VALUES] */ } , 
                            function(data)
                            {
                                if(data.response == 'success')
                                {
                                    //some code
                                    $('#submit-vote').attr('disabled', false).data('disabled',false); //enable button
                                    return true;
                                }
                                else
                                { 
                                    //some code
                                    $('#submit-vote').attr('disabled', false).data('disabled',false); //enable button
                                    return false; 
                                } 
                            }, "json"); 
                        }
                    }
                );
            });
    

    Docs: http://api.jquery.com/data/

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

Sidebar

Related Questions

I have a survey type form, and in a number of the questions, the
I have a survey-type form that's being populated from a web database on the
I have a basic quiz/survey type application I'm working on, and I'd like to
I have a small survey, but when i submit it says that the msg
I know, I quite dislike the catch-all survey type questions, but I couldn't think
I have a survey on a website, and there seems to be some issues
I have a survey application, where users can create surveys and give choices for
I have essentially a survey that is shown, and people answer questions a lot
I have a set of survey data, and I'd like to generate plots of
I have a task to make a survey to be displayed in SharePoint 2007

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.