How to call a variable that is in another file?

Asked

Viewed 1,162 times

-1

I have a "Y.php" file that returns in one of the inputs, the resulting calculation of other inputs within this same file, I do this using Jquery and is working 100%.

However, I would like to use the result of this calculation that is stored in the variable "X" in another input contained in the file "Z.php". That is, I want to use the value of this input (contained in "Z.php") as a result of another input contained in the file "Y.php".

How do I do this with Javascript?

require ('apNaoCirculantes.php'); //arquivo onde está a input na qual desejo pegar o valor
            var totaldeparred; // é o variável da input
            var campo16; // já estou no arquivo Z.PHP
            campo16 === totaldeparred;
            $("#depreciacao1").maskMoney('mask', totaldeparred); //minha input #depreciacao1 recebe o valor contido em totaldeparred

That’s it?

  • Can you do this via include or Ajax? Your question has gotten kind of distant.

  • Whatever, I can test the simplest solution?

  • So the easiest way is to make a include. So the input with the value you want to pick up will be on the same page and can catch this result with JS.

  • You can cite an example of this include?

  • require('pagina.php');

  • From what I understand, you want to open the Z.php page and take the value contained in an input of the Y.php page, that’s it?

  • yes, I want the input value that is in Y.php and put it in the input contained in Z.php.

  • This I understood. But the page you want to open is Z.php?

  • Yes, exactly.

  • I will elaborate an answer with the concept of this, since there is no exact code, then you test.

Show 5 more comments

1 answer

2


Include the Y.php file at the beginning of <body> page Z.php:

<?php require('Y.php'); ?>

Then take the value of <input> for id (if the input has a id) desired coming from the Y.php page and put in the <input> page Z.php:

<script>
document.getElementById("id_do_input_em_Z.php").value = document.getElementById("id_do_input_em_Y.php").value;
</script>
  • It worked perfectly. Thank you.

Browser other questions tagged

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