SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

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

    2 issues with number of buttons selected

    Got 2 problems with my buttons selection.

    What happens is the user selects the number of buttons depending on the number entered in the text box. If the number is 3 in the text box, then the user can only select 3 buttons, if more buttons are selected then it comes with an alert message saying user is beyond limit deselect a button to be able to choose another button.

    But these are the problems I have encounted:

    If I type in "2" in the textbox for example, it allows me to select 2 buttons and comes up with alert if more buttons clicked.

    problem 1: but if I change the figure in text box from "2" to "5", then it only allows me to select 3 buttons (I think it is adding 2 from the previous value and 3 to make the current value 5)

    problem 2: If I enter a value less than current value, so in this example if I enter in 1 in the textbox which is obviously less than 2, then it lets the user select unlimited number of buttons.

    So does anyone know how to fix these problems so that the amount of buttons selected matches correctly to the value in the textbox?

    code is in jsfiddle, click [here][1]

    Thanks


    [1]: http://jsfiddle.net/7WwaK/10/

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by malcolm p View Post
    So does anyone know how to fix these problems so that the amount of buttons selected matches correctly to the value in the textbox?
    You need to reset the currenttotal counter when you also reset the 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
  •