SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I do not selected buttons to go back to being unselected if option changes

    I have a grid of buttons the user can select from by opening the grid and selecting a button. Now if the user selects a button from the grid then it displays buttons "A" to whatever letter depending on the option selected from the grid. Now lets say the user clicks on the "Select All Answers" buttons, all buttons from "A" to whichever button turns green. Now if user decides to select another option from the grid, then what happens is that all the buttons that have been selected turns back to being unselected (turns back to a white color).

    I do not want this to happen. If the user clicks a button from the grid then I do not want it to remove all selected buttons underneath, I want it to stay the same as what it was.

    I want the same if the user changes the value in the "Number of Answers" textbox, I do not want it to turn selected buttons to being unselected.

    How can this be done?

    Code is in Jsfiddle, Click [here][1]


    [1]: http://jsfiddle.net/aMmNL/9/

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by malcolm p View Post
    I have a grid of buttons the user can select from by opening the grid and selecting a button. Now if the user selects a button from the grid then it displays buttons "A" to whatever letter depending on the option selected from the grid. Now lets say the user clicks on the "Select All Answers" buttons, all buttons from "A" to whichever button turns green. Now if user decides to select another option from the grid, then what happens is that all the buttons that have been selected turns back to being unselected (turns back to a white color).

    I do not want this to happen. If the user clicks a button from the grid then I do not want it to remove all selected buttons underneath, I want it to stay the same as what it was.

    I want the same if the user changes the value in the "Number of Answers" textbox, I do not want it to turn selected buttons to being unselected.

    How can this be done?
    You need to remove that fromCharCode line at the start of the for loop, and adjust the code so that's it's constantly checking for answerBtnsOn (and not answerBtnsOff)
    That can be done by changing:
    if ($(btn).hasClass("answerBtnsOff")) {
    to
    if (!$(btn).hasClass("answerBtnsOn")) {

    Finally, if a value is in Number of Answers, you need to set it to the number of currently visible and selected answer buttons.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •