I have a variable that I’m calling in php and showing in a input field for the user by default, to make some calculations, but the user can change the value. I’m using javascript to get the value, but it doesnt update. Its value always keeps the default value.
Share
Um… several things here…
Firstly, we don’t have any code. So we have no idea what you’re trying to do.
So I’m going to assume you’re talking about some sort of global variable (if you just declare
$foo = 10somewhere in your script you won’t be able to get it; the script is done parsing by the time the page is outputted).So let’s say you have
$_COOKIE['some_value']as the variable you want to change. The idea is you make an ajax call to some php file that will update it. So you might haveAnd you could make an ajax call using a library (jQuery here)
You can read more about ajax with jQuery here http://api.jquery.com/jQuery.ajax/
The example above also takes back any return data outputted by
change_value.php. So you could update change_value.php to change the value if specified, then output the (new) value regardless (so you could grab it).Of course, with cookies you could do that directly with javascript, but that’s just an example. If you had sessions the same approach could be used.