<form name="demo" method="GET">
<input name="test" value="">
</form>
<script>
document.demo.test.value=2;
</script>
<?
$s=$_GET[test];
echo $s;
?>
-
1you should know that javascript in the way you used it on your page is evaluated after the php has finished. the workflow is: php processing => delivering the resulting html => execution of the contained javascript in the client's browser. So the value you set will not be available in the php. EDIT: it will be available after the submission though.Andreas Grapentin– Andreas Grapentin2011-09-06 20:04:51 +00:00Commented Sep 6, 2011 at 20:04
Add a comment
|
2 Answers
JavaScript is a client-side language and PHP is a server-side language.
Any PHP variables are gotten and set on the server and then the processed before the page is then sent to the client (without any PHP code). Once the page loads on the client side, you can modify form values using javascript (but you obviously cannot change the value of the PHP variables at this point). If you change a form value using JavaScript and then submit that form to the server again, then you can get the new form value using PHP.