SitePoint Sponsor

User Tag List

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

    I want a more efficient way of coding to not display buttons

    I have two grids, they both display buttons. One grid displays numbers, true or false and yes or no, and the other grid displays letters, true, false, yes and no.

    The second grid is not displayed in the code (used css to not display second grid buttons (.answerBtns)) Now using the getButtons() function, if the user selects button "1" in first grid (the grid which you have to open using (Open Grid) link, then it should display button "A" in second grid, if user selects button "2" in first grid, then it should displays buttons "A" and "B" in second grid, if "3" then display "A", "B" and "C" and so on.

    Now except using if statements and stating which buttons should be displayed and not displayed depending on the button chosen in first grid, is there a more efficent way of coding this so that the display of buttons in second grid depends on what is selected in the first grid?

    If it is using an array can somebody show a sample of this in their answer. You can just do it for one example and then I should be able to use that to fill it for the other buttons.

    Thank you

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


  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Christchurch, New Zealand
    104 Post(s)
    4 Thread(s)
    Quote Originally Posted by malcolm p View Post
    If it is using an array can somebody show a sample of this in their answer.
    It sounds like a simple for loop will do the job there for you.

    You can have an area for that second grid just as an empty div:
    HTML Code:
    <div id="grid2"></div>
    and when an option is chosen, you can use a loop to create the buttons that you need:
    Code javascript:
    var $grid2 = $('#grid2'),
    for (i = 0; i < this.value; i += 1) {
        $grid2.append('<button>' + (i + 1) + '</button>');

    You may also want to hide that second grid when the "open grid" link is clicked too.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Posting Permissions

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