How to frame js of variable in php



  • We need to check the value. this.id key id
    I feel like I'm crazy, but I don't know how to do it right.

    <script type="text/javascript">
        ...
        if (confirm("Вы уверены?"))
            window.location = '<?=$this->createUrl('controller/action', ['id' => '<script type="text/javascript">this.id</script>']); ?>';
        ...
    </script>
    


  • If you need to act for a few buttons, like disposal, it's a code like this:

    <div class="delete" data-url-to-delete="<?=$this->createUrl('controller/action', array($id)); ?>">Удалить</div>
    <script type="text/javascript">
        document.querySelectorAll(".delete").forEach(function(el){
            el.addEventListener("click", function(e){
                var urlToDelete = el.getAttribute("data-url-to-delete");
                if (confirm("Вы уверены?"))
                    window.location = urlToDelete;
            });
        });
    </script>
    

    Or when pressed on the button, hand over the ID, in the processor generate URI and redirect URI.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2