How to create the javascript alert function for a specific page menu?

0

I have a page in PHP where I want to implement a JavaScript alert for when the user clicks the "Create a call" menu to return a message to the user. I did the implementation using the alert (), however the alert returns when the page is updated and it is not quite what I want the alert () to do on the page.

This is my PHP.

//  Create ticket
      if (Session::haveRight("ticket", CREATE)) {
         $menu['create_ticket']['id']      = "menu2";
         $menu['create_ticket']['default'] = '/front/helpdesk.public.php?create_ticket=1';
echo '<script type="text/javascript">alert("Retorne uma mensagem para o usuário ao clicar!");</script>';
         $menu['create_ticket']['title']   = __s('Create a ticket')
         $menu['create_ticket']['content'] = array(true);
      }

Because the code exceeds the character limit, I'll post the full page code below.

Link: Full Code

Source code of the page generated in HTML.

<!DOCTYPE html>
<html>

</script>
<a href="#" onclick="$('#loadbookmark').dialog('open');">
  <img src="/glpi/pics/bookmark.png" title="Carregar um favorito" alt="Carregar um favorito" class="button-icon">
</a>
</li>
<li id="help_link">
  <a href="http://glpi-project.org/help-helpdesk" target="_blank" title="Ajuda">
    <img src="/glpi/pics/help.png" title="Ajuda" alt="Ajuda" class="button-icon">
  </a>
</li>
</ul>
</div>
<div id="c_recherche"></div>
</div>
<div id="c_menu">
  <script type="text/javascript">
    alert("Retorne uma mensagem para o usuário ao clicar!");
  </script>
  <ul id="menu">
    <li id="menu1"><a href="/glpi/front/helpdesk.public.php" title="Home" class="itemP">Home</a>
    </li>
    <li id="menu2"><a href="/glpi/front/helpdesk.public.php?create_ticket=1" title="Cria um chamado" class="itemP">Cria um chamado</a>
    </li>
    <li id="menu3"><a href="/glpi/front/ticket.php" title="Chamados" class="itemP">Chamados</a>
    </li>
    <li id="menu4"><a href="/glpi/front/reservationitem.php" title="Reservas" class="itemP">Reservas</a>
    </li>
    <li id="menu5"><a href="/glpi/front/helpdesk.faq.php" title="FAQ" class="itemP">FAQ</a>
    </li>
  </ul>
  <script type="text/javascript">
    < /html>

But I am not able to implement the function that calls the alert for only the item in this menu and not for the entire page. Could someone help?

    
asked by anonymous 19.11.2016 / 16:30

3 answers

2

Would it be something like this?

<script type="text/javascript">
    function mostraAlerta() {
        alert("Retorne uma mensagem para o usuário ao clicar!");
    }
</script>
<ul id="menu">
    <li id="menu1"><a href="/glpi/front/helpdesk.public.php" title="Home" class="itemP">Home</a>
    </li>
    <li id="menu2"><a href="/glpi/front/helpdesk.public.php?create_ticket=1" title="Cria um chamado" class="itemP" onclick="mostraAlerta();">Cria um chamado</a>
    </li>
    <li id="menu3"><a href="/glpi/front/ticket.php" title="Chamados" class="itemP">Chamados</a>
    </li>
    <li id="menu4"><a href="/glpi/front/reservationitem.php" title="Reservas" class="itemP">Reservas</a>
    </li>
    <li id="menu5"><a href="/glpi/front/helpdesk.faq.php" title="FAQ" class="itemP">FAQ</a>
    </li>
</ul>
    
19.11.2016 / 19:23
0

For the source code of the generated HTML page, you seem to use jQuery on the page (I believe):

<a href="#" onclick="$('#loadbookmark').dialog('open');">

If this is the case and you want to run an alert () for the field:

<li id="menu2"><a href="/glpi/front/helpdesk.public.php?create_ticket=1" title="Cria um chamado" class="itemP">Cria um chamado</a>
</li>

You can add the following code in the header or footer of the page:

<script type="text/javascript">
$(document).ready(function(){
  $('#menu2').click(function(){
    alert("Retorne uma mensagem para o usuário ao clicar!");
  }) 
});
</script>

If you do not use jQuery, I think Michelle's example would work perfectly.

But you have to take into account if you want to show the alert and redirect the user, if it is to show information of what that menu link would be, maybe implement something like% a Bootstrap would be a good idea.

Note:

If you are going to print the php direct code, be sure to enclose the code in single quotation marks Tooltip if the javascript or html code has double quotation marks ''

    
20.11.2016 / 14:41
0

I recommend that you take a look at Modal Panel: link

You can put the panel html in the button call

    
21.11.2016 / 14:22