Implementation code for the transfer of variables between PHP and JavaScript
Source: Internet
Author: User
PHP variable to Javascript variable:
Copy the code code as follows:
<?php $myvar =10;?>
<script type= "Text/javascript" >
Jsvar = <?php echo $myvar;?>;
document.write (Jsvar); Test to see if its prints 10:
</script>
Form variable to Javascript variable:
Copy the code code as follows:
<form name= "MYFORM4" >
<input type= "hidden" name= "Formvar" value= ">"
</form>
<script type= "Text/javascript" >
Jsvar = Document.myform4.formvar.value;
document.write (Jsvar)//test
</script>
PHP variable to Form variable:
Copy the code code as follows:
<form name= "MYFORM4" >
<input type= "hidden" name= "Formvar" value= "<?php $phpvar = 10; echo $phpvar;?> ">/PHP code inside html!!
</form>
Javascript variable to Form variable:
Copy the code code as follows:
<form name= "MYFORM3" >
<!--It Needn ' t be a "hidden" type, but anything from radio buttons to check boxes-
<input type= "hidden" name= "Formvar" value= "" >
</form>
<script type= "Text/javascript" >
jsvar=10;
Document.myform3.formvar.value = Jsvar;
</script>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service