[英]how to show hidden form on load
I have a JSP page in which there are two forms. 我有一个JSP页面,其中有两种形式。
But when the output comes, the page gets loaded and shows the default form. 但是,当输出到来时,页面将被加载并显示默认表单。 I want to show hidden form instead.
我想显示隐藏形式。 What should I do?
我该怎么办?
My JSP page has following code structure: 我的JSP页面具有以下代码结构:
<div id="1st_form">
<form id="defaultForm" action="/searchModel/search">
%{-- form input fields--}%
<div style="float: left; margin-left: 15px;">
<a href="javascript:advancedSearch();" style="color: #ffffff; font-size: 13px;">Advanced Search</a>
</div>
</form>
</div>
<div id="2nd_form" hidden="hidden">
<form id="hiddenForm" action="/searchModel/search">
%{-- form input fields--}%
<input type="submit" id="searchButton" value="Advanced Search" >
<div style="float: left; margin-left: 15px;">
<a href="javascript:normalSearch();" style="color: #ffffff; font-size: 13px;">Advanced Search</a>
</div>
</form>
</div>
And javascript functions are as follows: 和javascript函数如下:
function advancedSearch(){
$("#1st_form").hide();
$("#2nd_form").show();
}
function normalSearch(){
$("#2nd_form").hide();
$("#1st_form").show();
}
The problem is, when you send any HTML page to the client, all changes you did with Javascript previously will be lost. 问题是,当您将任何HTML页面发送到客户端时,您之前使用Javascript所做的所有更改都会丢失。 That is why you see the default form visible again after submit.
这就是为什么您在提交后再次看到默认表单的原因。
What you want to do is: 您想要做的是:
When the "Advanced Search"-button is clicked, show the "Advances Search" form and make the "Default" form hidden in the response .
单击“高级搜索”按钮时,显示“高级搜索”表单,并将“默认”表单隐藏在响应中 。
What is something you need to do on server-side, because the client does not know which button submitted the form to the server. 您需要在服务器端执行什么操作,因为客户端不知道哪个按钮向服务器提交了表单。
So, you need check if the form was submitted by the "Advanced Search"-button on server side. 因此,您需要检查表单是否由服务器端的“高级搜索”按钮提交。 To be able to do this, you need to give the button a name:
为此,您需要给按钮命名:
<input type="submit" id="searchButton"
name="searchButton" value="Advanced Search" >
Now, when this button is clicked, it's value will be sent to the server . 现在,单击此按钮后, 其值将发送到服务器 。 In this case,
Advanced Search
. 在这种情况下,请使用
Advanced Search
。
Next, you need to check if this value was sent to the server in your JSP: 接下来,您需要检查此值是否已发送到JSP中的服务器:
<div id="1st_form" ${param.searchButton == 'Advanced Search'?'hidden':''} >
...
</div>
<div id="2nd_form" ${param.searchButton == 'Advanced Search'?'':'hidden'} >
...
</div>
Note: param
is an implicit object in Expression Language . 注意:
param
是Expression Language中的隐式对象 。
This way, when you first open the page, param.searchButton
will be empty and it will show the default search. 这样,当您第一次打开页面时,
param.searchButton
将为空,并显示默认搜索。 When the "Advanced Search" button was submitted, param.searchButton
will be Advanced Search
, and the advanced search will be visible. 当“高级搜索”按钮提交,
param.searchButton
会Advanced Search
和高级搜索将是可见的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.