PHP use onclick to perform another page function

Asked

Viewed 921 times

0

I have the following link in a header (header.php):

<a href="./index.php" id="btnMinhasReservas2" onclick="irParaMinhasReservas()" class="ph00_9"></a>

The idea is, when I click on this link, go to the index page and run a function called abreAba().
I’ll have to set something up in the file index js.?

  • 1

    If you need to use a function that is not of the page itself, that is, it is used by more than one, it would not be better to create a file apart?

1 answer

1

The answer is a little Gambi, but it can give you a light to improve.

Pass a parameter in the url warning the script to execute the function:

<a href="./index.php?acao=AbreAba" id="btnMinhasReservas2" onclick="irParaMinhasReservas()" class="ph00_9"></a>

In your php file you take this action and run it:

<?php

if (isset($_GET['AbreAba']) && $_GET['AbreAba'] != '') {
  abreAba();
}

This is not one of the best ways to do it, but it can give you a light to improve your logic there in this part.

  • I put it like this to test: <a onclick="abreAba(2,logged)" id="btnMinhasReservas2" class="ph00_9"></a> And then it works when I click (although the cursor does not flip the click cursor), but only if I’m on the index page.php. How can I show the click cursor and how can I do it when I’m on another PHP page of my site?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.