take value of a Function and put in a variable

Asked

Viewed 35 times

0

Personal how can I pass the attributes below in a variable?

<script>
$(document).on("click", "#btnInfoMaq", function () {
    var info = $(this).attr('data-id');
    var str = info.split('|');
    var serie_maquina = str[0];
    var grupo_maquina = str[1];
    $(".modal-body #serie_maquina").val(serie_maquina);
    $(".modal-body #grupo_maquina").val(grupo_maquina);
});


So... in the above script I pick up the data via a button!

<?php echo "<button class='btn btn-info' data-toggle='modal' data-target='#modalInfoMaq' id='btnInfoMaq' data-id='$serie_maquina|$grupo_maquina'> Informação</button>"?>

step them to a modal, with the above code... the problem is that in modal, I can only recover the information inside a hidel input... but what I wanted was to get this information inside a variable of php! to be able to carry out a consultation.

how can I take this information and put it into a variable $?

  • Clarify a little more detail about what you really want. You marked the php tag but wrote nothing about.

  • clarified below!

  • To include new information in the question, please use the [Edit] link above. Do not use the answer area below.

  • how could I solve this question? I have tried using <script>Document.write(serie_maquina)</script> but without success...

  • You want to add a certain value to a PHP variable via Javascript?

  • This... I want to take those two variables that are there in the java script... serie_maquina e grupo_maquina and put their value in a php variable.

  • 1

    PHP has already finished running when Javascript runs. If you really need to pass a value to PHP (to save or query something in the database, for example), you will need to use Ajax.

  • and how can I do that ? example!

  • Has how I pass attributes by post to modal?

  • You need to explain better what you are trying to do, it is not very clear. Could [Dit] and supplement the question?

  • 1

    But what really happened when you click the #btnInfoMaq button ? The difficulty in answering it is due to the fact that it is not possible to reconstitute the problem. Please re-examine the question or edit it by adding more details as suggested by the colleague. Fact is that the execution order of PHP code and Javascript can affect the expected result.

Show 6 more comments
No answers

Browser other questions tagged

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