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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:42:55+00:00 2026-06-07T10:42:55+00:00

Below is the code of a read only textbox: <td> <input type=text name=numberAnswer class=numberAnswerTxt

  • 0

Below is the code of a read only textbox:

<td>
<input type="text" name="numberAnswer" class="numberAnswerTxt answertxt" id="mainNumberAnswerTxt" onChange="getButtons()" readonly="readonly" >
</td>

Below is the code which displays buttons A-G:

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

<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>

Finally below is the function where it turns on and off the letter buttons:

function btnclick(btn)
{
    var context = $(btn).parents('#optionAndAnswer');
    if (context.length == 0) {
        context = $(btn).parents('tr');
    }

    if ($(btn).hasClass("answerBtnsOn")) {
        $(btn).removeClass("answerBtnsOn").addClass("answerBtnsOff");
        return false;
    }

    if ($(btn).hasClass("answerBtnsOff")) {
        $(btn).removeClass("answerBtnsOff").addClass("answerBtnsOn");
        return false;
    }

    $('.answertxt', context).val(context.find('.answerBtnsOn').length > 0 ? context.find('.answerBtnsOn').length : '');

}

What I have been trying to do in this function is that if the user has turned on a button , it should add the number in the texbox. For example, lets say all buttons are off, if I turn on button “B”, then the textbox should display number 1 in the textbox as one button is turned on, if I then turn on button “E”, it should display “2” in the textbox as two button are now turned on and etc. Also if I turn off button “E”, it should go back to displaying “1” in the textbox as only button “B” is turned on. In other words I want to keep track on how many buttons have been turned on.

How can I achieve this because at the moment nothing is being displayed in the text box when I turn a button on.

Here is the demo of the application:

When you open app just click on the “Open Grid” link and select a grid button, when letter buttons appear, then click on the buttons to turn on and off, as you can see nothing is displayd within the textbox.

  • 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-07T10:42:58+00:00Added an answer on June 7, 2026 at 10:42 am

    The line that calculates the number of buttons that have been turned on or off never gets hit because you have return false; right after you set the button classes. Try this:

    function btnclick(btn)
    {
        var context = $(btn).parents('#optionAndAnswer');
        if (context.length == 0) {
            context = $(btn).parents('tr');
        }
    
        if ($(btn).hasClass("answerBtnsOn")) {
            $(btn).removeClass("answerBtnsOn").addClass("answerBtnsOff");
        }
    
        if ($(btn).hasClass("answerBtnsOff")) {
            $(btn).removeClass("answerBtnsOff").addClass("answerBtnsOn");
        }
    
        $('.answertxt', context).val(context.find('.answerBtnsOn').length > 0 ? context.find('.answerBtnsOn').length : '');
    
        return false;
    }
    

    You may also want to try using jQuery’s .toggleClass() method. It was made for just this sort of thing.

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

Sidebar

Related Questions

I use the below code to create and read my database in the app
I have used the code below to read rfid tag values. try { if
I've read an article about 20 top jQuery tips that uses the below code
In the below code, using (SqlDataReader dr = com.ExecuteReader(CommandBehavior.CloseConnection)) { while (dr.Read()) { _emailTemplate.EmailContent
In the code below i`m trying to read a list of selected projects and
I was trying to read a lot of numbers dynamically using the code below
below code is my databasehandler class i got it from a tutorial. Beside that
I want to read below XML format only some attributes are required not All.
The below code only seems to POST the 'message' and nothing else. Is there
I'm wanting to create a read only text area in my app which allows

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.