0
 <form name="demo" method="GET">
<input name="test" value="">
 </form>
   <script>
 document.demo.test.value=2;
</script>


 <?
$s=$_GET[test];
echo $s;

  ?>
1
  • 1
    you 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. Commented Sep 6, 2011 at 20:04

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to do a submit to the same page (with ajax for example) for caught value via $_GET or $_POST

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.