skip to Main Content

hello i am trying to make popup Yes/No in js but is not working, this is my code:

one version is this:

if($admin==1) 
    print('<td><a href="delete.php?id='.$value. '"> <BUTTON class="btn btn-outline-info" onclick="AlertPopUp()" ><i class="fa fa-trash" style="color: #000000;"></i>  </BUTTON></a>');

function AlertPopUp(){
    let AlertPopUp = confirm("Are you sure you want to delete this client?");
    if(AlertPopUp){
        window.open('delete.php?id='+$value);
    }else{
        return;
    }
}

This is working but if i press cancel still deletes the value so i tried making the window.open but the url gets the value from php $value so i dont know how to pass it.

The other method i tried is this:

if($admin==1) 
    print('<td><a href="delete.php?id='.$value. '" onclick="return confirm('Are you sure you want to delete this client?');"> <BUTTON class="btn btn-outline-info" onclick="AlertPopUp()" ><i class="fa fa-trash" style="color: #000000;"></i>  </BUTTON></a>');

but this isnt working at all no popup appearing and the text isnt correct with ‘ ‘ so i tried " " but still nothing.

2

Answers


  1. As far as I understand you are working inside a PHP page, so it would be like this:
    first of all remove the <a> </a> and leave only the button because otherwise the link found in href will be opened.

    <? php $ admin = 1;  if ($ admin == 1) print ('<BUTTON class = "btn btn-outline-info" onclick = "AlertPopUp ()"> <i class = "fa-trash" style = "color: # 000000;" > </i> </BUTTON> '); ?>
    

    // then we harp the JS script

    <script>
    function AlertPopUp(){
        let AlertPopUp = confirm("Are you sure you want to delete this client?");
        if(AlertPopUp){
            window.open('delete.php?id=<?= $value ?>');
        }else{
            return;
        }
    }
    
    Login or Signup to reply.
  2. Try this:

    if($admin==1) 
        print('<td><BUTTON class="btn btn-outline-info" onclick="AlertPopUp('.$value.')" ><i class="fa fa-trash" style="color: #000000;"></i>  </BUTTON>');
    
    function AlertPopUp(value){
        let AlertPopUp = confirm("Are you sure you want to delete this client?");
        if(AlertPopUp){
            window.location.href='delete.php?id=' + value;
        }else{
            return;
        }
    

    You pass the php value as parameter and then fetch it from the function.

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