dcsimg
www.webdeveloper.com
Results 1 to 11 of 11

Thread: Lucky Draw - exclude drawn name

  1. #1
    Join Date
    Mar 2017
    Posts
    6

    Exclamation Lucky Draw - exclude drawn name

    Hi all,
    i have downloaded a simple lucky draw software, i have edit little bit, but i not sure how to exclude the name been drawn, so it will not appear in the next draw. Please help. thanks.


    function TrimString(sInString) {
    sInString = sInString.replace( /^\s+/g, "" );// strip leading
    return sInString.replace( /\s+$/g, "" );// strip trailing
    }

    function parseList(textarea) {
    var list_str = $(textarea).val();
    //var Array =
    var names = ["001 Amy", "002 BOB", "003 Cathy"];


    var list_lines = list_str.split("\n");
    for (var i = 0; i < list_lines.length; i++) {
    var name = TrimString(list_lines[i]);
    if (name != "") names.push(name);
    }

    return names;
    }

    $(document).ready(function() {
    var t;

    function startRolling() {
    var names = $("#name_list").data('names');
    var start_idx = $("#name_list").data('start_idx');

    var idx_1 = start_idx % names.length;
    var idx_2 = (start_idx + 1) % names.length;
    var idx_3 = (start_idx + 2) % names.length;
    var idx_4 = (start_idx + 3) % names.length;
    var idx_5 = (start_idx + 4) % names.length;
    $("#draw-1 .text").text(names[idx_1]);
    $("#draw-2 .text").text(names[idx_2]);
    $("#draw-3 .text").text(names[idx_3]);
    $("#draw-4 .text").text(names[idx_4]);
    $("#draw-5 .text").text(names[idx_5]);

    $("#name_list").data('start_idx', idx_2);
    }

    $("#switch").button();
    $("#switch").data("status", "stopped");
    $("#switch").data("origin_text", $("#switch").text());
    $("#switch").click(function(){
    if ($("#switch").data("status") == "stopped") {
    $("#switch").data("status", "rolling");

    $("#switch").text("STOP!");

    names = parseList("#name_list");
    $("#name_list").data('names', names);
    $("#name_list").data('start_idx', 0);

    intervalID = setInterval(startRolling, 80);


    } else {
    clearInterval(intervalID);
    $("#switch").data("status", "stopped");
    $("#switch").text($("#switch").data("origin_text") );


    }

    });
    });

  2. #2
    Join Date
    Dec 2012
    Posts
    1,549
    Please post the HTML too and use code tags: Click on "Go Advanced" bottom right and in the new window click the button containing the "#".

  3. #3
    Join Date
    Dec 2005
    Location
    TX
    Posts
    7,916
    Code:
    var names = ["001 Amy", "002 BOB", "003 Cathy"],  // could also be shuffled prior to use
         pick;
    // .....
    pick = names.shift();  // or = names.pop();
    // repeat above as needed until names array is empty, then reload array

  4. #4
    Join Date
    Mar 2017
    Posts
    6
    hi, dont get you. can you amend on the code? thanks.

  5. #5
    Join Date
    Mar 2017
    Posts
    6

    Html

    Quote Originally Posted by Sempervivum View Post
    Please post the HTML too and use code tags: Click on "Go Advanced" bottom right and in the new window click the button containing the "#".
    Code:
    <html>
        <head> 
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
            <title>JLuckyDraw</title> 
            <meta name="author" content="JsLiang Huiee" /> 
            <link rel="stylesheet" href="jquery-ui-1.8.16.custom.css" type="text/css" />
            <link rel="stylesheet" href="style.css" type="text/css" />
            <style type="text/css">
            body {
    	background-image: url(images/ui-bg_diagonals-medium_20_d34d17_40x40.gif);
    	background-repeat: repeat;
    }
            </style>
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
            <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
            <script src="jluckydraw.js" type="text/javascript"></script>
        </head> 
    
        <body>
            <div id="container">
                <div id="list_pane">
                       Lucky Draw
    <textarea id="name_list" style="display:none;">
    
    </textarea>
    
                </div>
                <div id="draw_pane">
                    <div id="draw">
                        <div id="draw-1" class="draw-a"><div class="text">&nbsp;</div></div>
                        <div id="draw-2" class="draw-b"><div class="text">&nbsp;</div></div>
                        <div id="draw-3" class="draw-c"><div class="text">&nbsp;</div></div>
                        <div id="draw-4" class="draw-b"><div class="text">&nbsp;</div></div>
                        <div id="draw-5" class="draw-a"><div class="text">&nbsp;</div></div>
                    </div>
                    <button id="switch">START
                </div>
            </div>
            <div id="footer">
                EVENTS
            </div>
        </body> 
         
    </html>
    Last edited by huiee; 03-19-2017 at 12:09 AM.

  6. #6
    Join Date
    Mar 2017
    Posts
    6
    evey time when i click the button, there will have "text" stop in draw-3, i want that to be remove when i click Start button again, so it will not be draw again.
    Last edited by huiee; 03-19-2017 at 12:08 AM.

  7. #7
    Join Date
    Mar 2017
    Posts
    6
    i try few times to post the HTML code but it keep prompt me to error page

  8. #8
    Join Date
    Dec 2005
    Location
    TX
    Posts
    7,916
    Quote Originally Posted by huiee View Post
    hi, dont get you. can you amend on the code? thanks.
    To whom are you referring?

  9. #9
    Join Date
    Mar 2017
    Posts
    6
    Quote Originally Posted by JMRKER View Post
    To whom are you referring?
    you.
    Evey time when i click the button, there will have "text" stop in draw-3, i want that to be remove when i click Start button again, so it will not be draw again.

  10. #10
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,415
    When asking a JQuery question, please use the JavaScript Frameworks forum as thats for JQuery questions
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  11. #11
    Join Date
    Dec 2005
    Location
    TX
    Posts
    7,916

    Lightbulb

    Not a JQuery solution, but you should be able to incorporate the logic into your program.

    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <title> Text Picker from Array </title>
    </head>
    <body>
    <textarea id="TArea" cols="30" rows="20"></textarea>
    <button onclick="pickName()">Pick name</button>
    
    <script>
    var names = ["001 Amy", "002 BOB", "003 Cathy"],  // could also be shuffled prior to use
        picknames = [].concat(names),
        pick;
    // .....
    // pick = names.shift();  // or = names.pop();
    // repeat above as needed until names array is empty, then reload array
    
    function pickName() {
      if (picknames.length-1 < 0) { picknames = [].concat(names); } // shuffle here if desired
      document.getElementById('TArea').value += picknames.shift()+'\n';
    }
    </script>
    
    </body>
    </html>
    Good Luck!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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