I am trying to present my html form data in servletby mixing two different javascript codes together:
<script type="text/javascript">
$(document).ready(function() {
$("#form1").validate({
rules: {
name: "required",
email: {
required: true,
email: true
},
url: {
url: true
},
comment: {
required: true
}
},
messages: {
comment: "Please Enter Your Message."
},
submitHandler:function(login_form){
$(login_form).ajaxSubmit({
target: '#msg-box',
success: function() {
$('#form1').slideUp('slow', function(){
$(".show_hide").show();
});
}
});
}
});
});
</script>
and the second - (obtained from this textbook):
<script type="text/javascript">
$(document).ready(function(){
$("#login_frm").submit(function(){
$("#msgbox").removeClass().addClass('myinfo').text('Validating Your Login ').fadeIn(1000);
this.timer = setTimeout(function () {
$.ajax({
url: 'check.jsp',
data: 'un='+ $('#login_id').val() +'&pw=' + $('#password').val(),
type: 'post',
success: function(msg){
if(msg != 'ERROR')
{
$("#msgbox").html('Login Verified, Logging in.....').addClass('myinfo').fadeTo(900,1,
function()
{
document.location='login.jsp?user='+msg;
});
}
else
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
$(this).html('Sorry, Wrong Combination Of Username And Password.').removeClass().addClass('myerror').fadeTo(900,1);
});
}
}
});
}, 200);
return false;
});
});
</script>
I'm not javascript or jQuery ninja, anyone please help me combine them with codes together.
One thing is that I have to make a lot of changes to the code submitHandler, but I try to do this without success.
PS: any best ideas for validating and submitting a jsp-jquery-ajax form are welcome.
source
share