简单 jQuery 表单验证并将有效数据发送给其他 jsp
Simple jQuery form validation and sending valid DATA to other jsp
- 我想验证这个东西并将这个值发送到其他 JSP 页面..
- 我是这个概念的新手。我需要你帮助“更正此表格”并在更正后建议我。我怎样才能将值发送到其他页面。
这里:- 只应输入一个字段。在两个字段或 2_fields.NULL()
的情况下显示警告。 [我做了 <span id="error"> some thing wrong<span/>
]
$(document).ready(function(event) {
<!-- Real-time Validation -->
var is_name=$('#contact_name').val();
var is_number=$('#contact_number').val();
$("#contact_submit button").click(function() {
if(($('#contact_number').val().length !=0) && ($('#contact_name').val().length !=0)) {
$("#nosearch").hide();
$("#search").hide();
$("#wrong").show();
}
else if (($('#contact_number').val().length ==0) && ($('#contact_number').val().length ==0) ) {
$("#nosearch").show();
$("#search").hide();
$("#wrong").hide();
}
else {
$("#nosearch").hide();
$("#search").show();
$("#wrong").hide();
// I know some action type of thing should happen here ..
// I don't know what it would be .. help me ...
}
});
$("#nosearch").show();
$("#search").hide();
$("#wrong").hide();
});
<form id="contact" method="post" action=" **i don't know how to send a value to other page** ">
<div>
<label for="contact_name">Number:</label>
<input type="text" id="contact_number" size="15" name="number"></input>
</div>
<div>
<label for="contact_email">Name:</label>
<input type="text" id="contact_name" size="25" name="name"></input>
</div>
<div id="contact_submit">
<button type="submit">Submit</button>
</div>
<h4 id="wrong"> Only use one column ...<h4>
<h4 id="nosearch"> Enter any Information <h4>
<h4 id="search"> Result about :- .... <h4>
</form>
好的,据我了解,您想要将表单参数从一个 jsp 页面发送到其他
首先将您的表单操作更改为其他页面名称,比如 other.jsp
<form id="contact" method="post" action="other.jsp">
然后创建一个jsp页面名称other.jsp并获取参数do
的值
<%
String para= request.getParameter("parameterName"); //name or number which is specified in form
%>
要打印它
<%=para%>
这里,是你正在使用的东西,
<div id="contact_submit">
<button type="submit">Submit</button>
</div>
submit
按钮用于提交表单。但是,在您使用的验证机制中,
$("#contact_submit button").click(function() {
如果您使用
,哪个会起作用
<input type="button">Submit</button>
所以,基本上 submit
事件会中和您的点击事件。因此,要么同样更改您的按钮,要么使用不同的 event
进行验证。
如果你使用点击事件,那么你应该在正确的验证情况下手动触发提交,
$("#contact_submit button").click(function() {
if(valid){
$("#form-id").submit();
}
但是,您也可以使用表单 submit
事件;它会在您单击提交按钮后立即触发。在那里,您可以通过检查正确的大小写来继续表单提交或拒绝表单提交。
$("#form-id").submit(function(){
if(invalid){
//Suppress form submit
return false;
}else{
return true;
}
});
这是第二种情况的working fiddle。
- 我想验证这个东西并将这个值发送到其他 JSP 页面..
- 我是这个概念的新手。我需要你帮助“更正此表格”并在更正后建议我。我怎样才能将值发送到其他页面。
这里:- 只应输入一个字段。在两个字段或
2_fields.NULL()
的情况下显示警告。 [我做了<span id="error"> some thing wrong<span/>
]$(document).ready(function(event) { <!-- Real-time Validation --> var is_name=$('#contact_name').val(); var is_number=$('#contact_number').val(); $("#contact_submit button").click(function() { if(($('#contact_number').val().length !=0) && ($('#contact_name').val().length !=0)) { $("#nosearch").hide(); $("#search").hide(); $("#wrong").show(); } else if (($('#contact_number').val().length ==0) && ($('#contact_number').val().length ==0) ) { $("#nosearch").show(); $("#search").hide(); $("#wrong").hide(); } else { $("#nosearch").hide(); $("#search").show(); $("#wrong").hide(); // I know some action type of thing should happen here .. // I don't know what it would be .. help me ... } }); $("#nosearch").show(); $("#search").hide(); $("#wrong").hide(); });
<form id="contact" method="post" action=" **i don't know how to send a value to other page** "> <div> <label for="contact_name">Number:</label> <input type="text" id="contact_number" size="15" name="number"></input> </div> <div> <label for="contact_email">Name:</label> <input type="text" id="contact_name" size="25" name="name"></input> </div> <div id="contact_submit"> <button type="submit">Submit</button> </div> <h4 id="wrong"> Only use one column ...<h4> <h4 id="nosearch"> Enter any Information <h4> <h4 id="search"> Result about :- .... <h4> </form>
好的,据我了解,您想要将表单参数从一个 jsp 页面发送到其他
首先将您的表单操作更改为其他页面名称,比如 other.jsp
<form id="contact" method="post" action="other.jsp">
然后创建一个jsp页面名称other.jsp并获取参数do
的值<%
String para= request.getParameter("parameterName"); //name or number which is specified in form
%>
要打印它
<%=para%>
这里,是你正在使用的东西,
<div id="contact_submit">
<button type="submit">Submit</button>
</div>
submit
按钮用于提交表单。但是,在您使用的验证机制中,
$("#contact_submit button").click(function() {
如果您使用
,哪个会起作用<input type="button">Submit</button>
所以,基本上 submit
事件会中和您的点击事件。因此,要么同样更改您的按钮,要么使用不同的 event
进行验证。
如果你使用点击事件,那么你应该在正确的验证情况下手动触发提交,
$("#contact_submit button").click(function() {
if(valid){
$("#form-id").submit();
}
但是,您也可以使用表单 submit
事件;它会在您单击提交按钮后立即触发。在那里,您可以通过检查正确的大小写来继续表单提交或拒绝表单提交。
$("#form-id").submit(function(){
if(invalid){
//Suppress form submit
return false;
}else{
return true;
}
});