How to assign HTML textbox value into PHP variable and vice versa on same page.

searchsanjaysharma used Ask the Experts™
1. How to assign HTML Textbox value into a PHP variable through Function.
2. How to assign PHP variable into HTML variable.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
A HTML textbox could be either a <INPUT TYPE="text"> or a <TEXTAREA>.
They usually get a name assigned:

<INPUT TYPE="text" NAME="textfield1">

They are usually part of a form, that, when submitted sends its form data to the script defined in the action attribute:

<FORM ACTION="/mysite/script.php" METHOD="POST">

The method will decide on how the variable will be transferred and how you can access it from PHP.

Posting will give all the form data as part of the $_POST array.
Using the GET method will make you use the $_GET array.

If you use the example above, the contents of the text box will be available by reading the variable $_POST['textfield1'].
can you please elaborate the question...from what i need to know how to send data in an html textarea into a php script, and then change the content in the textarea to what the php script would return? or are the two tasks unrelated?
1- assign HTML textbox to PHP variable.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" size="15" name="var1" />
<input type="submit" value="assign" />

$var =$_POST["var1"];
// now you can do wtf you want with the variable.
2-HTML doesn't have is not a programming language so it does have variables
you may use javascript - vbscript.
echo "<script type="/text/JavaScript"/> ";
echo "var my_var = $country" ;
echo "</script>";

Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

sorry for the typo
2- HTML doesn't have variables you may use Javascript or vbscript.


I means to say the value is to be assigned to HTML textbox, it is self understood.
here's the answer to your number 2.

<textarea name="whatever"><?php echo $text;?></textarea>

just put whatever you want to appear inside the textarea within the tags.



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial