Please Help Me Out :

I want to compare some condition like (check the user id exist in database or not)Trough Jquery,

If it lie it show error image
else it show the confirmed image!

Any One help me out!

Have a look at the sample here:
http://roshanbh.com.np/2008/04/ajax-login-validation-php-jquery.html

HTP

Sir actually i wana done it without submitting page
I write down the code here which i had done:

<html>
    <head>
        <link rel="stylesheet" href="../menu.css" type="text/css">
         <link rel=stylesheet" href="admin.css" type="text/css">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <script type="text/javascript" src="../jquery.js"></script>
         <script type="text/javascript">
             $("document").ready(function(){
                 $("#p1").hide();

                $("#b1").click(function(){
                 
                 $("#t1").hide();
                 $("#p1").show(200);
             });



                         $("#p11").click(function(){
                 $("#t1").hide();
                 $("#p1").show(200);
             });


             });

             
         </script>
        <title>Admin Manage</title>
        
         </head>
    <body>

        <%
        //String sel=request.getQueryString();
%>
        <%@include file="session.jsp" %>
        
        <%@include file="bannermenu.jsp" %>
        <br>
        <br>
        <table id="t1" align="center">
            <tr>
                <td id="b1">
                    <a class="adminbutton" href="#" onclick="">
                    Insert New
                        </a>
                    <script></script>
                </td>
                <td id="b2">
                    <a class="adminbutton" href="delete.jsp?u" onclick="">
                    Update an Record
                    </a>
                </td>
                <td id="b3">
                    <a class="adminbutton" href="delete.jsp?d" onclick="">
                    Delete the Record
                    </a>
                </td>
            </tr>
        </table>

        <div id="p1">
            <%@include file="new.jsp" %>
        </div>
    </body>
</html>

And new.jsp

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>SHO Submission</title>
        <link rel="text/css" href="../menu.css" type="text/css">
        <script type="text/javascript" src="../jquery.js"></script>
         <script type="text/javascript">
             function abc(){

                         $("#p11").click(function(){
                 $("#t1").hide();
                 $("#p1").show(200);
             });


             };


         </script>
        <script type="text/javascript">
              function popup()
            {
                alert("Database Updated")
            }
        </script>
        
    </head>
    <body>
       
        <%
String sel=request.getQueryString();
String path="";
String res="";
%>
        
       <%@include file="../connection.jsp" %>
                <div>

                     <%
           String name="";
                        String address="";
                        String password="";
                        String Mobile_no="";
                        String Mail_id="";
                        String Gender="";
                        String ID="";
                        String sid=request.getParameter("sid");
                        address=request.getParameter("address");
                        password=request.getParameter("pwd");
                        Mobile_no=request.getParameter("contact");
                        
                        Gender=request.getParameter("Gender");
                        
		 %>
	
	<%

                  if(request.getParameter("check")!=null)
                      {
ID=request.getParameter("ID");
                        name=request.getParameter("name");
                        Mail_id=request.getParameter("mail");
        try
		{
			
                        rs=smt.executeQuery("select * from IPS where ID='"+ID+"' and designation='"+sel+"' ");
                      if(rs.next())
                          {
                         // out.println("Find");
                          path="../images/unavail.jpg";
                          res="30px";
                          }
                        else
                            {
                           // out.println("Not-Find");
                            path="../images/avail.gif";
                            res="20px";
                        }
                      }
        catch(Exception ex)
                {
        ex.getMessage();
        }


        }
                    if(request.getParameter("submit")!=null)
                        {
                        

        try
		{
			
                        smt.execute("insert into IPS values('"+ID+"', '"+password+"', '"+name+"', '"+Mobile_no+"', '"+address+"', '"+Gender+"', '"+Mail_id+"','Enable','"+sel+"')");
                        smt.execute("insert into Officer values('"+sid+"','"+ID+"','"+name+"','"+Mobile_no+"','"+sel+"')");
                        }
        catch( Exception e)
                {
            out.println(e);
            }
                    }
          %>
                    <form action="#" method="post">
                        <fieldset style="margin: 140px; margin-left: 220px; margin-right: 170px;">
                            <legend>
                        ADD <%=sel %>
                    </legend>
                        <table align="center">
                           <tr>
                               <td>
                        <label for="Name">Name </label></td>
                               <td> <input id="name" type="text" name="name" value="<%=name%>"/><br>
                        </td>
                        </tr>
                        <tr>
                        <td><label for="Email">Email address </label></td>
                        <td> <input id="Email" type="text" name="mail" value="<%=Mail_id%>" /><br></td>
                       </tr>
                    
                       <tr>
                     <td><label for="ID">Enter New ID </label></td>
                     <td> <input type="text" id="Email" name="ID" value="<%=ID%>"><br></td>
                     
                       
                       
                     <td id="p11"><input type="button" name="check" value="Check!" > </td>
                    
                       <%

                  if(request.getParameter("check")!=null)
                      {
ID=request.getParameter("ID");
                        name=request.getParameter("name");
                        Mail_id=request.getParameter("mail");
        try
		{

                        rs=smt.executeQuery("select * from IPS where ID='"+ID+"' and designation='"+sel+"' ");
                      if(rs.next())
                          {
                         // out.println("Find");
                          path="../images/unavail.jpg";
                          res="30px";
                          }
                        else
                            {
                           // out.println("Not-Find");
                            path="../images/avail.gif";
                            res="20px";
                        }
                      }
        catch(Exception ex)
                {
        ex.getMessage();
        }


        }
%>
                       <td  ><img src="<%=path %>" alt="" width="<%=res %>" height="<%=res %>"> </td>
                       </tr>
                        
                       <tr>
             <td>
                 Station ID
             </td>
             <td>
                 <select name="sid" >
<%
try
                                {

     rs=smt.executeQuery("select * from Stations");
     while(rs.next())
         {
         %>
         
                     <option ><%=rs.getString(1) %> </option>
               
         <%
         }
    }
catch(Exception ex)
        {
    ex.getMessage();
}
%>
                          </select>
             </td>
         </tr>

                       <tr>
                       <td> <label for="password">Password </label></td>
                       <td> <input id="Email" type="password" name="pwd"><br></td>
                       </tr>
                       <tr>
                           <td>
                        <label for="password">Confirm Password </label></td>
                       <td> <input id="Email" type="password" name="R_pwd"><br></td>
                       <tr>
                       <td> <label for="contact">Contact No. </label></td>
                       <td> <input id="Email" type="text" name="contact"><br></td>
                       </tr>
                       <tr>
                           <td>
                        <label for="Gender">Gender </label></td>
                       <td> <select name="Gender">
                            <option>Sex</option>
                            <option value="Male">Male</option>
                            <option value="Female">Female</option>
                        </select><br></td>
                       </tr>
                       <tr>
                       <td> <label for="Message">Address </label></td>
                      <td>  <textarea id="Message" rows="3" cols="20" name="address"></textarea><br></td>
                      </tr
                      <tr>
                          <td></td>
                          <td>
                              <input  type="submit" name="submit" onclick="popup()" value="Submit" /></td>
                          </tr>
                          </table>
                   </fieldset>
                    </form>
                </div>
           
        
    </body>
</html>

Whenever i click on check button it again show me the first page automatically

Member Avatar for stbuchok

Use Ajax and web services. The web service will be created using a serverside language like ASP.Net or PHP. The link below is only for the jQuery AJAX implementation and doesn't explain anything about web services. That you will need to Google depending on what language you will be using for it.

http://api.jquery.com/jQuery.ajax/

Use Ajax and web services. The web service will be created using a serverside language like ASP.Net or PHP. The link below is only for the jQuery AJAX implementation and doesn't explain anything about web services. That you will need to Google depending on what language you will be using for it.

http://api.jquery.com/jQuery.ajax/

I use the JSP for this !!!!!

Member Avatar for stbuchok

OK, so you have a webservice you can use written in JSP and you are able to make an AJAX call to that web service, correct? If so, where exactly do you need help then as you have everything you need.

OK, so you have a webservice you can use written in JSP and you are able to make an AJAX call to that web service, correct? If so, where exactly do you need help then as you have everything you need.

Actually , When i click on first page button it will give me the Right output(include the New.jsp) and show me the from of New.JSP on the manage.jsp by using include the page ,

But when i press the check button to check the user id Exist or not then it reload the page and give the first page again!!!

Member Avatar for stbuchok

On click of the button, make an call to a javascript function that returns true if the ID exists and false if it doesn't. In the JavaScript function make an AJAX call to check for the existence of the ID.

<script>

function doesIDExist(){
    var results = AjaxCall();
    var returnValue = false;

    if(results > 0){
        returnValue true;
    }

    return returnValue;
}

</script>

<input type="submit" value="Check ID" onclick="return doesIDExist();" />

Please know that the above code is just to show you the structure and doesn't actually work.

By returning false from the function you will cancel the click event and no postback will be created.

On click of the button, make an call to a javascript function that returns true if the ID exists and false if it doesn't. In the JavaScript function make an AJAX call to check for the existence of the ID.

<script>

function doesIDExist(){
    var results = AjaxCall();
    var returnValue = false;

    if(results > 0){
        returnValue true;
    }

    return returnValue;
}

</script>

<input type="submit" value="Check ID" onclick="return doesIDExist();" />

Please know that the above code is just to show you the structure and doesn't actually work.

By returning false from the function you will cancel the click event and no postback will be created.

I done it same , but still not working

Member Avatar for stbuchok

Can you show your code that does this? I've looked at the code above and all of them will give a postback. Also you will want to use parameterized stored procedures. Right now I would be able to drop your entire database as you are just writing out the SQL.

Can you show your code that does this? I've looked at the code above and all of them will give a postback. Also you will want to use parameterized stored procedures. Right now I would be able to drop your entire database as you are just writing out the SQL.

Sir , give me your ID i will give you live demo of my problem when you are online at FB or Gtalk

Member Avatar for stbuchok

You can PM me here if you'd like.

Click on Insert Button , then check any id existence then see the problem

Member Avatar for stbuchok

You might want to remove this, it's not a private message. I'm pretty sure everyone can see it.

You might want to remove this, it's not a private message. I'm pretty sure everyone can see it.

Not tension this link automatically expire after 20 min ,,

sir any advise to resole it !

You might want to remove this, it's not a private message. I'm pretty sure everyone can see it.

Please tell me how to stop the Check button reload error?????????

Member Avatar for stbuchok

OK, I just got home, and like I said, you need to send me a private message with code or a link to the site so that I can see. I know you put up a link before, but you had usernames and passwords that were publicly visible. So please, private message me with the information or I can't help you. Also I can only view your site at my house as my work blocks it.

So chances are I'll only be able to look at it over the weekend.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.