Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Ajax ajax doubdt
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


anitha.a
ajax doubdt
1 Answer(s)      2 years and 4 months ago
Posted in : Ajax


function getentityshortname(val) {

alert("entered");

var centrecode=val;
var unitcode=val;

var postString = "&centrecode="+centrecode; var postString = "&unitcode="+unitcode;

//   alert(postString);

    var url='getentitydata.jsp';
    //window.open(url);
    //alert(url);
    if (window.XMLHttpRequest)
    {
        req = new XMLHttpRequest();
    } 
    if (window.ActiveXObject)
    {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    req.onreadystatechange = entityshortnamedetails;                            //handling response

    req.open("post", url, true);
    req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    req.setRequestHeader('Content-length', 'parameters.length');
    req.send(postString);
    //document.forms[0].action=url;
    //document.forms[0].submit();

} /******************************/ function entityshortnamedetails() { if (req.readyState == 4) { if (req.status == 200) { var rset=new Array(); rset=req.responseText; rset=rset.replace(/^\s+|\s+$/g,""); var list2=new Array(); list2=rset.split('~'); var spacetrim = /,\s+/;

    if(document.employee.cmbentity.length > 0)  //loop for clearing already existed values in a combo
        {
               document.employee.cmbentity.length= 0;  
        }
        /*values assignment */

        document.employee.cmbentity.options[0] = new Option();
                document.employee.cmbentity.options[0].text="--select--";
              for(var i=0,j=1; i < list2.length-1; i++,j++)
                {
                document.employee.cmbentity.options[j] = new Option();
                document.employee.cmbentity.options[j].text=list2[i].split(spacetrim);

                }
        /*values assignment */





    }
    else 
    {
        alert ("Unable to get Data" +req.responseText);
    }
}

} /******************************/ can we use val twice in the above


Advertisement
View Answers

June 19, 2012 at 5:34 PM


Here is an example of ajax that will display the database values in the textboxes by getting the id through another textbox.

1)ajax.jsp:

<%@page import="java.sql.*"%>
<html>
<head>
<script type="text/javascript">
function showData(){ 
xmlHttp=GetXmlHttpObject()
    var id=document.getElementById("id").value;
var url="getdata.jsp";
url=url+"?id="+id;
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(){ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 

  var showdata = xmlHttp.responseText; 
    var strar = showdata.split(":");
      if(strar.length>1)
         {
        var strname = strar[1];
        document.getElementById("name").value= strar[1];
        document.getElementById("address").value= strar[2];
         }

 } 
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
  xmlHttp=new XMLHttpRequest();
 }
catch(e){
 try{
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch(e){
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
</script>
</head>
<body>
<br><br>
<table >
<tr><td>Client ID:</td><td><input type="text" id="id" name="id" onkeyup="showData();"></td></tr>
<tr><td>Name:</td><td><input type="text" id="name" name="name"></td></tr>
<tr><td>Address:</td><td><input type="text" id="address" name="address"></td></tr>
</table>
</body>

2)getdata.jsp:

    <%@ page import="java.sql.*" %> 
    <%
    int id = Integer.parseInt(request.getParameter("id"));

     String data=" ";  
     try{
      Class.forName("com.mysql.jdbc.Driver");
               Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
     Statement stmt = con.createStatement();  
     ResultSet rs = stmt.executeQuery("Select * from addclients where clientid  ="+id+"");  
       while(rs.next())
                    {
                        data = ":" + rs.getString("name") + ": " + rs.getString("address");
                    }
                    out.println(data);
      }
     catch(Exception e){
    System.out.println(e);
     }

 %>
</html>


Related Tutorials/Questions & Answers:
ajax doubdt
ajax doubdt  function getentityshortname(val) { alert("entered"); var centrecode=val; var unitcode=val; var postString = "&centrecode... of ajax that will display the database values in the textboxes by getting the id
Ajax
Ajax  How to learn AJAX
Advertisements
ajax
ajax  please describe the ajax
Ajax
Ajax  Hi, What is Ajax? What is the use of Ajax? Thanks   Hi, Ajax is set of technologies used to develop dynamic web applications. In Ajax following technologies is used: a) JavaScript b) XML c) HTTP d) CSS Learn
Ajax
Ajax  how to impliment ajax in registration table using jsp-servlet
Ajax
Ajax  send the example to fetch the data from the server by using ajax in java. for ex:-if there are states which is used to display in frontend we use ajax. send it to me
Ajax
Ajax  how to include ajax in jsp page?   Hi, Please read Ajax First Example - Print Date and Time example. Instead of using PHP you can write your code in JSP. Thanks
ajax
ajax  how to connect ajax with mysql without using php,asp or any other scripting language. please answer soon
Ajax - Ajax
Ajax  What is Ajax ? How one can use ajax with Java
ajax
ajax  HI, In my application using ajax if i type a managername in the textbox it should display all the employees under the that manager... me reg this. thanks KK   Combobox box using Ajax in JSP   i
Ajax
in a tabular form. Same for >33kv We can use ajax where instead of a link a radio button can fetch the data and can populate a table.If ajax can be used
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
Ajax
options. I want to do it using ajax. My table is CREATE TABLE HT<em>
AJAX
ajax. My table is CREATE TABLE HTNEWMETER ( ID NUMBER (10) NOT NULL, METERNO
ajax
ajax  I am facing following problem, I am using ajax to get the data continousely without refreshing. Here i have devided a web page into 3 parts(top,left and right) using table in jsp. On the left part i am displaying some
AJAX - Ajax
AJAX  what is Ajax?WHAT IS THE USAGE OF IT?WHERE WE HAVE TO USE IT? GIVE ME EXPLANATION WITH EXAMPLE?  Hi friend, Ajax : Asynchronous JavaScript and XML or Ajax for short is new web development technique used
AJAX - Ajax
AJAX  What is AJAX?how we will use it in java?what is the use of AJAX?give me example?   hi friend, Ajax plays a major role... characteristics have made it popular among the users to develop their site using Ajax
ajax - Ajax
ajax  Hi all, I want ajax validation in struts1.0 , I tried from many days but, i cound't find solution.. I am attaching my code here. struts... ("Your browser does not support Ajax HTTP"); return; } var s
ajax - Ajax
ajax  Dear Roseindia, I want small application using ajax validation in struts1 login. I tried from many days but, i coudn't get solution..Do some favour me..it's urgent. Thanqs for advance.   Hi
Ajax - Ajax
that : form1.html where all Ajax code is written : function showHint...){ alert ("Your browser does not support AJAX!"); return
AJAX - Ajax
("Your browser does not support AJAX!"); return; } var url="http://localhost
AJAX with
AJAX with       Ajax resources, in a digg style, allows the user to register and addd his/her own links Read full Description
What is ajax? - Ajax
What is ajax?  What is Ajax Programming? Can any one share the basic examples of it? thanks
Ajax Learner - Ajax
Ajax Learner  Hi, This is Ziaul,I am working as Java/j2ee Developer from last one year. i have to use Ajax for my current project.pls guide me how should i proceed to learn Ajax. Thanks and Regards Ziaul Hauqe Siddique 
Ajax validation - Ajax
Ajax validation  how to validate a form using Ajax and php  ... you. Please visit for more informaton: http://www.roseindia.net/ajax/ajaxlogin/ajax-registration-program.shtml Thanks. Amardeep
Ajax Learner - Ajax
Ajax Learner  Hi, This is Ziaul,I am working as Java/j2ee Developer from last one year. i have to use Ajax for my current project.pls guide me how should i proceed to learn Ajax. Thanks and Regards Ziaul Hauqe Siddique 
ajax basics - Ajax
ajax basics  i need ajax basics where can i find these........................ pls help me thanx in advance  Hi friend, Ajax : Asynchronous JavaScript and XML or Ajax for short is new web development technique
ajax with php - Ajax
ajax with php  how to do autocomplete search using ajax wit php in object oriented format?.. data should me retrive from database.. plz the way?.. give some sample codings
 

 

 

DMCA.com