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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:51:32+00:00 2026-06-07T03:51:32+00:00

Got a bunch of letter buttons in code below: Code: <?php $a = range(A,Z);

  • 0

Got a bunch of letter buttons in code below:

Code:

<?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>
</table>

Now the code below is able to turn on an answer button:

Code:

function addwindow(btn) { 
$('#answer'+btn).addClass("answerBtnsOn");
}

But the only problem is that the code above is only able to turn on a single answer button on only. For example if the “Answer” is B, then it will look for button "#answerB" and turn on that button which is button B. or if the “Answer” is E, then it will look for button "#answerE" and turn on that button which is button E.

The problem is that if there are multiple answers. If the “Answer” is B E, then it does not turn on buttons B and E. This is because it is trying to find button "#answerBE" which is incorrect, it should be looking for button "#answerB" and button "#answerE" and turn them both on.

Another example is if “Answer” is A D F, it doesn’t turn on buttons A D and F because it is trying to find button "#answerADF" which is incorrect, it should be looking for button "#answerA", button "#answerD", and button "#answerF" and turn them all on.

So my question is that how can I turn on multiple buttons if there are multiple Answers? Do I need to put all the buttons in an array and loop through them so that it is able to go through all the buttons and turn on those buttons which should be turn on?

UPDATE:

Below is the “Add” button which calls on the addwindow() function and above the add button is the “Answer” column where it displays rows of Answers

   echo '<td class="noofanswerstd">'.htmlspecialchars($searchNoofAnswers[$key]).'</td>';
    echo "<td class='addtd'><button type='button' class='add' onclick=\"parent.addwindow('$searchAnswer[$key]');\">Add</button></td></tr>";
  • 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-07T03:51:33+00:00Added an answer on June 7, 2026 at 3:51 am

    I believe,you need this:

    function addwindow(btn) { 
        var answers = $.map(btn.split(''),function(chr){   return "#answer"+chr;  }).join(', ');
        $(answers).addClass("answerBtnsOn");
    }
    

    Explanation:

    btn.split('')   //splits btn string into char's array, 
                    //  e.g. "ADE" will become ["A","D","E"]
    $.map           //converts ["A","D","E"] 
                    //  to ["#answerA","#answerD","#answerE"]
    join(',')       //makes "#answerA, #answerD, #answerE" string 
                    //  from ["#answerA","#answerD","#answerE"] array
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got a bunch of letter buttons in code below: <?php $a = range(A,Z); ?>
I just got a bunch of legacy VB6 (!) code dumped on me and
I've got a bunch of legacy Guile Scheme code that I want to get
I've got a bunch of legacy code that I need to write unit tests
I'm got a bunch of html code like this: <a href=http://example.com/project-a title=Project A (test)>Project
I've got a string with a bunch of multi-letter codes in it and I'd
I got a bunch of NSLog statements in my code. Is there anyway I
I've got a bunch of IDL files filled with enums. I would like a
I've got a bunch of lists <ul> <li class=first>Item 1</li> <li>Item 2</li> <li class=last>Item
I've got a bunch of text like this: foo bar baz What's likely to

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.