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


    [1]: http://jsfiddle.net/m2aP2/7/

  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
    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'),
        i;
    ...
    $grid2.empty();
    for (i = 0; i < this.value; i += 1) {
        $grid2.append('<button>' + (i + 1) + '</button>');
    }
    $grid2.show();

    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


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
  •