How to automatially go to the otherpage after clearing some fields?

80 Views Asked by At

I am making a scratchcard game and I need to know how to check if everything is cleared to go to the next page. i will show u a part of the code i have

i got nine of these scratch pads and i want to go to the other page when they are cleared all nine:

    var images = [], 
        index = 0;

        images[0] = "images/slide1.jpg";
        images[1] = "images/slide2.jpg";
        images[2] = "images/slide3.jpg";
        images[3] = "images/logo.jpg";
        images[4] = "images/winner.png";
        images[5] = "images/scratch-to-win.png";

        index = Math.floor(Math.random() * images.length);

        $('#nummer9').wScratchPad({
          scratchMove: function (e, percent) {
            console.log(percent);
            if (percent > 70)
            {
                this.clear();
            }
          }
        });
        $("#nummer9").wScratchPad('bg', images[index]);
        $("#nummer9").wScratchPad('fg', 'images/overlay.png');
        $("#nummer9").wScratchPad('size', '15');
        $("#nummer9").wScratchPad('cursor', 'url("./images/coin.png") 5 5, default');

And i need to know what i have to put inside this if statement.

    if ()
        {
            window.alert('alle vakjes zijn open gekrast');
            window.location.href="geenprijs.php";
        }
1

There are 1 best solutions below

1
On
    var images = [], 
    var cleared = 0;
    index = 0;

    images[0] = "images/slide1.jpg";
    images[1] = "images/slide2.jpg";
    images[2] = "images/slide3.jpg";
    images[3] = "images/logo.jpg";
    images[4] = "images/winner.png";
    images[5] = "images/scratch-to-win.png";

    index = Math.floor(Math.random() * images.length);

    $('#nummer9').wScratchPad({
      scratchMove: function (e, percent) {
        console.log(percent);
        if (percent > 70)
        {
            this.clear();
            cleared++;
        }
      }
    });
    $("#nummer9").wScratchPad('bg', images[index]);
    $("#nummer9").wScratchPad('fg', 'images/overlay.png');
    $("#nummer9").wScratchPad('size', '15');
    $("#nummer9").wScratchPad('cursor', 'url("./images/coin.png") 5 5, default');

Then

    if (cleared === 9)
    {
        window.alert('alle vakjes zijn open gekrast');
        window.location.href="geenprijs.php";
    }