1
I have the following field on the "index.php page":
<input type="hidden" id="exemplo" value="<?php $varExemplo; ?>">
I would like to take the value of this field on another page using jQuery.
var exemploIndex = $("#exemplo").val();
Would that be? Or would you need to declare the form as well? Thank you very much!
First, we missed one
echo
to define the attributevalue
field. Second, use jQuery to pick up the value on another page? What do you mean? You are submitting this form to a PHP file and want to get the value in this file?– Woss
Thanks for the reply Anderson, the echo I just did not put there in the example, but in the code is present. So, before submitting the form, there is a "select" that takes a parameter from the page that I need to send this variable (example), my initial idea was to change this "select" the way I wanted, but it is used on more pages so it would give "caca", and this "page", I ended up expressing myself badly, is a JS file with some functions among them to which I need to receive this value, to compare with the value of "select" mentioned earlier. Thanks!
– Lucas MWP
Still very confused. What is this
select
? What are these files?– Woss
Hehehe, this select is an input in which it shows some products, it is generated from a function that is in this JS file. I have two possibilities in my weak logic, one where I can send the value together with that select, or that I can just send and receive a value in that function from any input other than select.
– Lucas MWP
If all the files cited are JS and all are included in the page that has the form, yes, it would be something like you put in the question:
$("#exemplo").val()
.– Woss
Cool, so would I just use the "id" of the input? Don’t I need to declare the form that this input belongs to? Sorry for the ignorance...
– Lucas MWP
Yes, just the
id
, for theid
defines a single element on the whole page. There is no way to have two elements with the sameid
, then you don’t need to tell us where the element is located.– Woss
All right, Anderson, I’ll try it here, thank you very much for your help and patience!
– Lucas MWP
@Lucasmwp If you want to send the value of this
input="hidden"
for another page, you need a<form method="post">
and make a Submit, and on the other page receive this field with$_POST['nome_do_campo']
. Wouldn’t that be?– Sam
@Lucasmwp And still give a
name
to the field instead of aid
.– Sam