Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to pass the java script value to the php block. I try many code, but i con't complete the task...


Any one please help
Posted
Updated 13-Apr-12 22:52pm
v2

Javascript runs on the client (browser), PHP runs on the server. The only way Javascript code can communicate with PHP code is by making a HTTP request. AJAX[^] may be a solution to your problems.
 
Share this answer
 
Agree with markkuk

You may use AJAX or have to post the data from your javascript so that the server side PHP will pick it up something similar to this..

create a file called test.php

and try the following code and it may give you a solution

XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="JavaScript">
function Test(num)
{

    window.location.href = "test.php?myval=" + num;
}
</script>
</head>
<body>


        <p><input type="button" value="Test Java script!" onClick="Test(100);" ></p>

<?php
echo('PHP BLOCK');

if (isset($_GET['myval']))
{
echo "VALUE PASSED  : ".$_GET['myval']."<br>";
}
?>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900