0

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...

Thanks,
Shubhada

5
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by Gilette
0

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"/>
</form>

The the sending string will show:

formreceiver.php?myText=Hello

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:

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

It is tested and verified on a LAMP server.

0

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(){
  $value=document.getElementById("myText").value;
  $info='<form name="myForm" method="get" action="formreceiver.php">';
  $info+='<input type="hidden" name="myText" value="'+$value+'" >';
  $info+='</form>';
  document.getElementById("myForm").innerHTML=$info;
  document.myForm.submit();
}
</script>

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

Edited by Gilette: n/a

0

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:

<?php
$msg="?";
if(isset($_GET['myText'])){printSmiley($_GET['myText']);}
function printSmiley($myText){
  global $msg;
  switch($myText){
    case "happy" : 
      echo "The smiley is happy";
      $msg="sad";
      break;
    case "sad" : 
      echo "The smiley is sad";
      $msg="happy";
      break;
    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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.