JS is the front-end language, PHP is the background language, and the front and back-end are often unclear at the beginning (I did it at the beginning, and now I am also committing a crime ), my original idea was to regard the frontend and backend as two islands. They cannot be crossed. HTML is like a bridge. When you want to pass the variables on one island to another, only with the help of this bridge.
Let me make a small summary:
1: how to upload the values in HTML to JS? The following is a file named 1.php.
Copy codeThe Code is as follows: <Body>
<Form action = "1.php" method =" post ">
Name: <input type = "text" name = "username" id = "username">
Rename: <input type = "text" name = "username1" id = "username1">
<Input type = "button" value = "submit" on CliCk = "get ()">
</Form>
</Body>
</Html>
JS, if you want to get the name value entered by the user in the text box, writeCopy codeThe Code is as follows: <script language = 'javascript '>
Function get ()
{
Var n = document. getElementById ('username'). value;
Alert (n );
} </Script>
In this case, a warning box will pop up when JS get () is called, and the content in the box is the value of name.
2: If the name value obtained in JS is to be returned to the rename text box, write
Copy codeThe Code is as follows: <script language = 'javascript '>
Function get ()
{
Var n = document. getElementById ('username'). value;
Document. getElementById ("username1"). value = n;
} </Script>
In this way, calling get () below will automatically display the value entered by your name above.
3: Get the page value in PHP
I think everyone will.Copy codeThe Code is as follows: <? Php
$ Name = $ _ REQUEST ["username"];
Echo $ name;
?>
4: PHP value returned to the page
Insert the PHP language into HTML. You can call the value of the variable in PHP or use Smarty (recommended ).
With the above, both the values on the HTML page and the values of the JS variables can be easily imported into PHP. Of course, the values of PHP can also be uploaded to the desired place.