locked
create Random number without refresh RRS feed

  • Question

  • User-1000681580 posted

    hi

    i have a label on layout and two buttons called "Start" and "Stop" . now when user click on start button then create random numbers and show in the label . also when user click on stop button , it be stop.

    please help me for solve it

    thanks

    Tuesday, February 13, 2018 7:06 AM

Answers

  • User1400794712 posted

    Hi asreniazmandiha,

    You can use Javascripts to make it. There is a Math.floor(Math.random()) function to generate random number.

    <label id="randomNum">0</label>
    <input type="button" id="Start" value="Start" />
    <input type="button" id="Stop" value="Stop" />
    @section scripts{
        <script>
            $(function () {
                var randomNumber;
                $("#Start").click(function () {
                    clearInterval(randomNumber);
                    randomNumber = setInterval(function () { 
                        $('#randomNum').text(Math.floor(Math.random() * 101)); }, 100);
                })
                $("#Stop").click(function () {
                    clearInterval(randomNumber);
                })
            })
        </script>
    }

    How it works:

    Best Regards,

    Daisy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 13, 2018 11:22 AM