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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:32:40+00:00 2026-06-12T06:32:40+00:00

I have a multiple row of buttons in my javascript code which goes from

  • 0

I have a multiple row of buttons in my javascript code which goes from A-Z:

<?php
    $a = range("A","Z");
?>

<table id="answerSection">
    <tr>

<?php
    $i = 1;
    foreach($a as $key => $val){
        if($i%7 == 1) echo"<tr><td>";
        echo"<input type=\"button\" onclick=\"btnclick(this);\" value=\"$val\" id=\"answer".$val."\" name=\"answer".$val."Name\" class=\"answerBtns answers answerBtnsOff\">";      
        if($i%7 == 0) echo"</td></tr>";
        $i++;
    }
?>
    </tr>

Below is the javascript function where it turns on and off each individual button:

function btnclick(btn)
{


$(btn).toggleClass("answerBtnsOff");
$(btn).toggleClass("answerBtnsOn");

    return false;
}

I want to perform a $_POST so that it posts all of the buttons which has been turned on. Does anyone know how the post method should be written for this?

  • 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-06-12T06:32:42+00:00Added an answer on June 12, 2026 at 6:32 am

    I would suggest adding a hidden field together with the buttons turned on with the same name as the button. That way you will have the POSTs returned to you with values. This code is not tested but it should work something like this:

    <?php
    $a = range("A","Z");
    ?>
    
    <table id="answerSection">
    <tr>
    
    <?php
    $i = 1;
    foreach($a as $key => $val){
        if($i%7 == 1) echo"<tr><td>";
        echo"<input type=\"button\" onclick=\"btnclick(this);\" value=\"$val\" id=\"answer".$val."\" name=\"answer".$val."Name\" class=\"answerBtns answers answerBtnsOff\">";
        echo"<input type=\"hidden\" value=\"1\" id=\"hiddenAnswer".$val."\" name=\"hidden".$val."\" class=\"onButtons\">";
        if($i%7 == 0) echo"</td></tr>";
        $i++;
    }
    ?>
    </tr>
    

    With the following JavaScript (assuming you are using jQuery):

    function btnclick(btn)
    {
        $(btn).toggleClass("answerBtnsOff");
        $(btn).toggleClass("answerBtnsOn");
    
        var hiddenId = '#hiddenAnswer'+btn.value;
        if ( $(btn).hasClass("answerBtnsOff") )
        {
            $(hiddenId).val('0');
            $(hiddenId).toggleClass('offButtons');
            $(hiddenId).toggleClass('onButtons');       
        }
        else
        {
            $(hiddenId).val('1');
            $(hiddenId).toggleClass('onButtons');
            $(hiddenId).toggleClass('offButtons');
        }   
    
        return false;
    }
    

    So if your buttons have the $val’s ‘Hello’, ‘World’, ‘Foo’, ‘Bar’ you will receive the following posts where they are either 1 (button turned on) or 0 (button turned off):

    $_POST['hiddenHello']
    $_POST['hiddenWorld']
    $_POST['hiddenFoo']
    $_POST['hiddenBar']
    

    Notice that all buttons are “turned on” from the start.

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

Sidebar

Related Questions

Ok, I have a table which contains multiple rows. Each row contains some data
I have a parent grid that contains multiple row definitions, all of which have
Lets say I have multiple commands like 5000 which updates some column and row
I have a table with multiple rows in each row is a select list
I have multiple ajax requests with javascript code as response, and I need to
I have a table that contains multiple rows. Each row contains 5 columns (or
I have multiple table rows that has a set of radio buttons on each
In this jsfiddle http://jsfiddle.net/littlesandra88/eGRRb/ have I submit buttons that are auto-generated. Each table row
I have a table with multiple rows, with each row having a button within
I have multiple buttons in gridview. How can i determine which particular button on

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.