Hello all,
I have same problem.
in javascript i called php fun using <?php fun1()?>. it run successfully. But i want to pass variable to that function which is a value of input text box.
i.e var tt=document.getElementById('cname');
and i want to pass that tt value to php function.

How to do this?
Please help...


How do you want the variable to be passed? Without reloading the page?

If u have an input form in a html body like this:

<form name="myForm" method="get" action="formreceiver.php">
<input type="text" name="myText" />
<input type="submit" value="Submit"/>

The the sending string will show:


Then u can retrieve the value from the form input in php file called "formreceiver.php" and at the same time print it out like this:

if(isset($_GET['myText'])){echo "The text input is: " . $_GET['myText'];}

It is tested and verified on a LAMP server.

U can also omit the static html form and make it on the fly with Javascript. Still, u need some html like this:

<input type="text" id="myText" />
<input type="button" value="Submit" onclick="javascript:setSubmit();"/>
<div id="myForm"></div>

And to run it, the Javascript can look like this:

<script type="text/javascript" language="javascript">
function setSubmit(){
  $info='<form name="myForm" method="get" action="formreceiver.php">';
  $info+='<input type="hidden" name="myText" value="'+$value+'" >';

The php file called "formreceiver.php" in previous reply can be used.
It is tested and verified on a LAMP server.

You can also use AJAX to pass the variable behind the scenes so to speak.

Using a php file only to change a value displayed from within a php variable to a html dom value and back to php for valuation, this example would be enough to satisfy the requirements:

function printSmiley($myText){
  global $msg;
    case "happy" : 
      echo "The smiley is happy";
    case "sad" : 
      echo "The smiley is sad";
    default : break;
echo '
<form name="myForm" method="get" action="myText.php">
<input type="text" name="myText" value="'.$msg.'"/>
<input type="submit" value="Submit"/>

The php file is called "myText.php".
It is tested and verified on a LAMP server.

Here's an article on your subject "" can you help it