JSP and JS Interaction Problem value transfer

Source: Internet
Author: User

1. Access the value returned by JS in JSP:
Problem: CopyCode The Code is as follows: <script language = "JavaScript">
<! --
VaR STR = "123 ";
<%
String AA;
%>
-->
</SCRIPT>

How can I obtain the STR value in Javascript from AA in this JSP ????
The details are as follows:Copy codeThe Code is as follows: <script language = "JavaScript">
Function returnvalue (){
VaR myform = Document. form1;
VaR STR = myform. text1.value;
<%
String AA;
// How can I make AA equal to STR in JS ???
%>
}
</SCRIPT>
<Form name = "form1">
<Input type = "text" name = "text1" onchange = "returnvalue ();">
</Form>

Solution:
It must be submitted because one is running on the client and the other is running on the server;
Use a hidden field in JSPCopy codeThe Code is as follows: <form name = "form1">
<Input type = "hidden" name = "hide">
</Form>
The script defines var STR = "123 ";
Document. form1.hide. value = STR;

Then, just take the value of hidden.
Problem Comment: In the old saying, JSP must be submitted for obtaining JS data, and JS can directly obtain JSP data.

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.