Well, come on!
When will you access such value in your PHP file? If you are not going to access such a value in PHP just store it in a Javascript variable (a global one).
To define a global variable just declare it outside of some function or (1), if the declaration is in a function one should not use the var
(2). Ex:
1:
var valor = 10;
function foo() {
return 'bar';
}
2:
function foo() {
valor = 10;
return 'bar';
}
If you really need to access such a value in your PHP file, just set the value
input with the PHP value and add a id
to identify the field (if you are going to make an Ajax request) or add the name
to receive such value in your PHP file.
Ex:
<input type="hidden" id="meuValor" name="nameValor" value="<?php echo $valor; ?>" />
And, after already having such value in your HTML just call functions in events, for example, onClick of some button, onKeyPress of some input, etc.
Hope I helped, hugs.
Welcome to Stack Overflow! You probably need to submit a request to access this variable through
$_POST
or$_GET
– Wallace Maxters
Something like:
$x = "<script>document.write($bookId);</script>"
, in which$bookId
has the value of$_POST['bookId']
already verified.– felipe.zkn
The
input
is not inside any form? You send the value of the field to the server via AJAX?– felipe.zkn
The input is not in any form and its value is not sent to the server , I only use it because I need to somehow save a value that was sent via javascript to the modal window. I wonder if there is a way to recover the value of this field and assign it to a PHP variable without accessing it by POST or GET.
– João Paulo