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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:26:43+00:00 2026-05-27T07:26:43+00:00

I have some buttons below in my HTML: <p> <input class=answerBtns name=answer type=button value=A

  • 0

I have some buttons below in my HTML:

<p>
<input class="answerBtns" name="answer" type="button" value="A" />
<input class="answerBtns" name="answer" type="button" value="B" />
<input class="answerBtns" name="answer" type="button" value="C" />
<input class="answerBtns" name="answer" type="button" value="D" />
<input class="answerBtns" name="answer" type="button" value="E" />
</p>

What I want to know if lets say I want the user to select 3 buttons for example, then if the user clicks on a button, it will highlight the button in a color (lets say green) but the user can only have three buttons selected. If an additional button is clicked then that button would not be selected. The additional button can only be selected if the user unselects a selected button and then selects the button he wishes. This means that only 3 buttons can be selected at maximum.

My question is that what functions in Javacsript can be used to be able to do this?

Thank You

  • 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-27T07:26:44+00:00Added an answer on May 27, 2026 at 7:26 am

    Firstly, you have to give your buttons different names.

    <input class="answerBtns" id="answer1" type="button" value="A" onclick="changeClass(this.id);" /> 
    <input class="answerBtns" id="answer2" type="button" value="B" onclick="changeClass(this.id);"/> 
    <input class="answerBtns" id="answer3" type="button" value="C" onclick="changeClass(this.id);"/> 
    <input class="answerBtns" id="answer4" type="button" value="D" onclick="changeClass(this.id);"/> 
    <input class="answerBtns" id="answer5" type="button" value="E" onclick="changeClass(this.id);"/>
    

    What I would suggest is using jquery to change the class of the button to something like answerBtnsSelected when a button is selected this, will also help you with your css styles to highlight the button.

    What you can then do is create a function that checks the amount of buttons with that class, and if it’s three or more then ignore or whatever, else change the class to make it selected.

    Added logic to unselect button

    function changeClass(id)
    {
        if ($('#' + id).hasClass('answerBtnsSelected'))
            $('#' + id).removeClass('answerBtnsSelected');
        else
        {
            if ($('.answerBtnsSelected').length < 3)
            {
                $('#' + id).addClass('answerBtnsSelected');
            }
            else
            {
                 alert('Only three buttons can be selected.');
            }       
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got below ASP html <div id=divCheckAll> <div class=selectall> <input type=checkbox id=chkOperationalUpdate name=chkOperationalUpdate
I have below html code <div id=divTest> Hello <input type=text id=txtID value= /> <input
I have an input element in HTML markup as below: <input type=text name=s id=s
I am have buttons like this: <button type=button class=img img_button_bla onclick=...>Bla!</button> The img class
I have got [hide] and [unhide] input buttons , the hide button shows some
I have a subclass s of UIView. I want to put some buttons and
I have a bit of code below that creates a button on a html
I have some buttons in an UIView. My problem is, that they get cut
I have some filter and one grid.And grid have some buttons like modify/edit.I am
In my application I have some link buttons there but when I right click

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.