skip to Main Content

I have a php code as shown below in which when Line A and Line B is executed, I want to display a Not Found popup message on click.

if (condition) {
    /*  
    
    code
    
    */
    if (file_exists($path)) {
        $choices[0][1] = 'display_file.php?path=' . addressencode($path);
    } else {
        $choices[0][1] = "Not found";   // Line A
    }
    continue;
}


if (1 == sizeof($choices)) {
    $address = $choices[0][1];
} 


<area shape="rect" href="<?php echo $address; ?>"
      onclick="if(this.getAttribute('href') !== 'changes need to be made here' && parent.document.body.rows == '*,0' ) parent.document.body.rows = '55%,45%';"
      alt="<?php echo implode(', ', $records); ?>" />  <!-- Line B -->
  

Problem Statement:

I am wondering what changes I need to make at Line A and especially at Line B, so that on click Not Found popup message is displayed.

2

Answers


  1. Try adding this below Line A.

      echo '<script type="text/javascript">
    
            alert("Not Found");
    
            </script>';
    
    Login or Signup to reply.
  2. You may attach an event listener on your <area> tag to show a popup or perform any operation on the element’s click.

    <area shape="rect" href="<?php echo $address; ?>" id="area"
          alt="<?php echo implode(', ', $records); ?>" />
    
    <script>
    
    const areaElement = document.querySelector("#area");
    
    areaElement.addEventListener("click",()=>{
        if(YOUR_CONDITION_HERE){   //Conditionally show the popup on click, if the popup should be shown every time on click regardless of the condition, consider removing the if block.
           alert("Not Found")
        }
     });
    </script>
    

    The script loads up initially during the page load, but the message is shown only on click and when the if condition is satisfied. This way you’ll not have to add the condition in the onclick attribute of the area tag and let JS handle the event by binding a listener to the element.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search