Question

I'm writing an exam code when the page is refreshed a next question is loaded.

There are other links on the page if any is clicked a conformation message should appear.

  • If Ok then go to the linked page.
  • If Cancel then stay on the same page.

The problem I'm having is that the page gets refreshed and have already loaded another question after the cancel button is clicked.

HTML:

<a href="/?link=1" name="link1"> HOME </a>

PHP:

 if(isset($_GET['link']))
 {
    $link=$_GET['link'];
    if ($link == 1){
        echo "<script>
        var r=confirm('There are no fields to generate a report');
        if (r==true)
        {
           window.location.href='evalhome.php';
        }
        else
        {
           relax();
        }
        </script>";
  }
Was it helpful?

Solution

make your links like this :

<a href="#" onclick="if(confirm('There are no fields to generate a report')) 
window.location='evalhome.php';else return false;" name="link1"> HOME </a>

if user clicks on it, he will see a confirmation, if he press ok, he will be redirected to evalhome.php . if not, stays in the same page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top