JSP and JS Interaction Problem value transfer

Source: Internet
Author: User

1. Access the value returned by JS in JSP:
Problem:
Copy codeThe 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 jsp
Copy 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.