White screen to run an alert js in php

0
        <?php
    // Start the session
    session_start();
    ?>

    <html>
    <head>

      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

      <!-- Bootstrap CSS -->
      <link rel="stylesheet" href="css/bootstrap.min.css">
      <link rel="stylesheet" href="css/css.css">
      <title>Pregunta 1</title>
  </head>
  <body>
    <form  method="POST" >
              <div id="login">
                <h4 class="text-center text-danger">Puntaje: <label class="text-dark"><?php echo $i=0; ?></label></h4>
                <h3 class="text-center text-white pt-4"><?php echo "Nombre del jugador: ".$_SESSION['nickname'];?></h3>
                <div class="container">
                    <div id="login-row" class="row justify-content-center align-items-center">
                        <div id="login-column" class="col-md-5">
                            <div class="login-box col-md-12">
                               <!-- <form id="login-form" class="form"  method="post"> -->
                                    <h3 class="text-center text-info">Primera Pregunta:</h3>
                                    <br><br>
                                    <div class="form-group">
                                        <label  class="text-info">Llamamos sujeto a:</label>

                                    </div>       
                                    <div >

                                       <center>                               
                                        <label  class="btn btn-primary btn-lg btn-block" > <font SIZE=2>A.Expresiones escritas </font><input type="checkbox"  name="check1" value="a"  class="badgebox"><span class="badge">&check;</span></label>
                                        <label  class="btn btn-primary btn-lg btn-block"><font SIZE=2> B. Un individuo que habla</font><input type="checkbox" name="check1" value="b" class="badgebox"><span class="badge">&check;</span></label>
                                        <label  class="btn btn-primary btn-lg btn-block"><font SIZE=2> C. La persona, animal o cosa que realiza la acción del verbo</font><input type="checkbox" name="check1" value="c" class="badgebox"><span class="badge">&check;</span></label>
                                        <label class="btn btn-primary btn-lg btn-block"><font SIZE=2> D. Las palabras agudas</font><input type="checkbox"  name="check1" value="d" class="badgebox"><span class="badge">&check;</span></label>
                                    </center> 

                                </div>            
                                <center>            
                                    <button type="submit" name="inicio" class="btn btn-danger btn-lg">Volver al inicio</button>
                                    &emsp;&emsp;&emsp;&emsp;&nbsp;
                                    <button type="submit" name="EnviarPrimera" class="btn btn-success btn-lg">&emsp;&emsp;Enviar&emsp;&emsp;</button>
                                </center>      

                            </form>

                        </div>
                    </div>
                </div>
            </div>
        </div>




    </body>

    <?php
    if (isset($_POST['EnviarPrimera'])) {

        $res =  $_POST['check1'];


        if ($res == "c") {
          $i++;
          ?>

          <SCRIPT type="text/javascript"> 
          function alertFunc(){
            alert("Respuesta Correcta");
            location.href = "pregunta2.php?i=<?php echo $i?>";
        }
        window.onload=alertFunc;

        </SCRIPT> 
        <?php

    } else {
     ?>
     <SCRIPT type="text/javascript"> 
        alert("Respuesta incorrecta");
        location.href = "pregunta2.php?i=<?php echo $i?>";
    </SCRIPT> 
    <?php
}
}if (isset($_POST['inicio'])) {
    header('Location: index.php');
}

     ?>
     </html>

When creating a form and showing the alert in Javascript , it shows me the alert ("Correct Answer"), but the background screen shows it white, I mean, I need to show the form that I made.

    
asked by jose ricardo 24.10.2018 в 18:10
source

2 answers

0

Apparently the flow of execution is good:
1) alert ("Wrong answer");
2) location.href="question2.php? I="; // - once you click on accept.

answered by 24.10.2018 в 18:46
0

I think you should look for another approach, it has to do with the alert function that runs in the main thread and blocks the rendering of the content, if you save it in a setTimeout it would work but it is not the best. Here's something about that alert () block render

google docs

setTimeout(() => {
  alert("Respuesta incorrecta");
}, 3000);
    
answered by 24.10.2018 в 19:20