Monday, 12 August 2013

submit a form using jquery, jsp without refreshing page

// siddhu vydyabhushana // 14 comments

Hai the readers of javatyro, today am going to explain the form submit in webpages without refresh or without changing the page . jQuery is a google library it has a capability to change the values on live change using $("slector").live() . i hope you will like the tutorial..
   
                                             DOWNLOAD TUTORIAL:click here 

Database  :

Validations using jquery
$(function() {
$(".submit").click(function() {
var name = $("#name").val();
	var username = $("#username").val();
	var password = $("#password").val();
	var gender = $("#gender").val();
	     
	
var dataString = 'name='+ name + '&username=' + username + '&password=' + password +
                     '&gender=' + gender;
	if(name=='' || username=='' || password=='' || gender=='')
	{
	$('.success').fadeOut(200).hide();
        $('.error').fadeOut(200).show();
    }
    else
	{
	$.ajax({
	type: "POST",
    url: "ajax-form.jsp",
    data: dataString,
    success: function(){
	$('.success').fadeIn(200).show();
    $('.error').fadeOut(200).hide();
}
});
}
return false;
});
});

ajax-form.jsp
<%@page import="java.sql.*"%>
<%
if(request.getParameter("name")!=null)
{
String name=request.getParameter("name");
String username=request.getParameter("username");
String password=request.getParameter("password");
String gender=request.getParameter("gender");

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:form");
Statement stmt=con.createStatement();
stmt.executeQuery("insert into login values('"+name+"','"+username+"',
'"+password+"','"+gender+"')");
con.close();
}
catch(Exception e)
{
out.println(e);
}
}
%>
your likes and shares makes me more happy like my page in fb

14 comments:

  1. Android Tutorial Basic to Advance: Click Here
    Android User Interface Tutorial: Click Here

    ReplyDelete
  2. For most business owners, making the decision to implement an IVR or voice response software is easy. Here are some tips for choosing IVRs and providers that will benefit you the most.
    Interactive Voice Response System

    ReplyDelete
  3. Thank you for sharing any nice information . I like to know more about what is new and i think that we must always learn from each other
    real estate
    cars
    free ads
    advertise for free

    ReplyDelete