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



Home Answers Viewqa JSP-Servlet Autopopulate values into textbox from database on pressing tab or on clicking
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


niharika gupta
Autopopulate values into textbox from database on pressing tab or on clicking
2 Answer(s)      3 years and 6 months ago
Posted in : JSP-Servlet


Hi, In my project we have to enter a productid which is first need to be searched into database. if it already exists then it will autopopulate its corresponding producttype,productprice into textboxes when we press tab or click on the producttype(which is first textbox related to product_id).This is need to be done before actual submission of form so kindly provide me related code.


Advertisement
View Answers

July 5, 2011 at 4:04 PM


1)checkid.jsp:

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

function showData(){ 
xmlHttp=GetXmlHttpObject()
    var id=document.getElementById("id").value;
var url="data.jsp";
url=url+"?id="+id;
xmlHttp.onreadystatechange=stateChanged1 
xmlHttp.open("GET",url,true)
xmlHttp.send(null);
}
function stateChanged1(){ 
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("type").value= strar[1];
        document.getElementById("price").value= strar[2];
         }
       } 
     }

</script>
</head>
<body>
<br><br>
<table >
<tr><td>ID:</td><td><input type="text" id="id" name="id" onkeyup="checkID();"></td></tr>
<tr><td>Product Type:</td><td><input type="text" id="type" name="name" onclick="showData();"></td></tr>
<tr><td>Price:</td><td><input type="text" id="price" name="address"></td></tr>
</table>
</body>
</html>


July 5, 2011 at 4:05 PM


2)id.jsp:

<%@ page import="java.sql.*" %> 
<%
String id = request.getParameter("id").toString();
System.out.println(id);
int count=0;
String data ="";
try{
           Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from item where itemid='"+id+"'");
while(rs.next())
{
count++;
}
if(count>0){
    data="It is a valid id";
}
else{
    data="It is not a valid id";
}
out.println(data);
System.out.println(data);
}
catch(Exception e) {
System.out.println(e);
}
%>

3)data.jsp:

<%@ page import="java.sql.*" %> 
<%
String id = request.getParameter("id").toString();
System.out.println(id);
String data ="";
try{
           Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from item where itemid='"+id+"'");
while(rs.next())
{
 data = ":" + rs.getString("item") + ": " + rs.getString("price");
}
  out.println(data);
  System.out.println(data);
}
catch(Exception e) {
System.out.println(e);
}
%>


Related Tutorials/Questions & Answers:
Autopopulate values into textbox from database on pressing tab or on clicking
Autopopulate values into textbox from database on pressing tab... to be searched into database. if it already exists then it will autopopulate its corresponding producttype,productprice into textboxes when we press tab or click
how to retreive values from MS Access Database based on the values entered in textbox values in jsp file
how to retreive values from MS Access Database based on the values entered in textbox values in jsp file  Hi am new to java. i need to create... Solution field from database and display in the textbox of the jsp.   1
Advertisements
Dynamically Update textbox from database
Dynamically Update textbox from database  I have a database as shown below.(database created using SQL Server 2005) name : george,simon address... to that typed value from database has to be displayed in another text box
display data from database in textbox when id entered in textbox
display data from database in textbox when id entered in textbox  i wanted to enter data in textbox .depending on entered data in textbox data from database should be displayed dynamically in textbox
Getting Textbox data from database
Getting Textbox data from database  When i m trying to get data in textbox as readonly from database i m getting following error.and my code is shown... data from database and display it on the textboxes. <%@page language="java
Getting Textbox data from database
Getting Textbox data from database  When i m trying to get data in textbox as readonly from database i m getting following error.and my code is shown...;Here is a jsp code that retrieves data from database and display
How to insert dynamic textbox values into database using Java?
How to insert dynamic textbox values into database using Java?  Hi I am trying to insert dynamic textbox values to database, my jsp form have 2... these dynamic textbox values to database(Oracle 11g)...Please help me out. I have
How to show data from database in textbox in jsp
How to show data from database in textbox in jsp   How to show data from database in textbox in jsp   Here is an example that retrieve the particular record from the database and display it in textbox using JSP. <
How to insert data from a combobox and textbox values into DB using JSP?
How to insert data from a combobox and textbox values into DB using JSP?  hi, How to insert a comb-box and a text box values in to DB using JSP? @DB:student; @table:stu_info; Combobox values:(class1,class2,class3); textbox1
how to get the values from dynamically generated textbox in java?
how to get the values from dynamically generated textbox in java?  I... textbox corresponding to the data. I want to get data from textboxes(generated as per the retrieved data) and I want to store textbox values into the two table
retrieve the data to text fields from database on clicking the value of combo box
retrieve the data to text fields from database on clicking the value of combo box   retrieve the data to text fields from database on clicking... getting data into textarea from database table by clicking on the button
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database.  Hii Sir, Lots of thnx to ur reply .I went through both... of selecting value from autocomplete textbox using jquery in jsp from mysql database
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database. ... but was unable to find out exact way to fullfill the solution of selecting value from autocomplete textbox using jquery in jsp from mysql database. Kindly send me
populating textbox value from the database using onchange function,
populating textbox value from the database using onchange function,  .... but the next textbox value is populated from database. plz help me guys... dynamically from the database(mysql). after selecting the value from the dropd
get values from Excel to database
get values from Excel to database   hi i want to insert values from Excel file into database.Whatever field and contents are there in excel file that should go to database which exists. am using SQL Server management studio
By dropdownlist retrive data from database and show in textbox in jsp.
By dropdownlist retrive data from database and show in textbox in jsp.  Hello Sir, I am doing project in jsp.I have to retrive data from database, when I select value from dropdownlist, and that data I want to show in textbox
How to show autocomplete textbox values on combo box option selection using database?
How to show autocomplete textbox values on combo box option selection using database?  When I select option(i.e First Year) then it will show list of student names in auto-complete text box
problem in setting the values from database
the values from database. here is the code: private JTextField getJTextField1...problem in setting the values from database  hello friends, can..."); PreparedStatement pst=con.prepareStatement("select * from form1 where TerminalID
retaining textbox values
retaining textbox values  i have a calculator program, when i press a button the value displays but disappears when i press another button so how can i keep values to display when i press multiple buttons
retrieving data from database to the textbox depending upon the id in jsp
retrieving data from database to the textbox depending upon the id in jsp  Hi, our project involves fetching of data from database into textbox depending upon another textbox value which is productid.First the id entered by us
insert values from excel file into database
the following link: Insert values from excel file to database...insert values from excel file into database   hi i want to insert values from Excel file into database.Whatever field and contents are there in excel
showing the information of database in textbox
showing the information of database in textbox  how to make a information of a database make appear to the user in the textbox
Retaining textBox values in java - Java Beginners
Retaining textBox values in java  Hi all, i have a jsp screen where i have two actions . I have a single textbox and two buttons. My textbox... in textbox for clicking on the second button. Is this possible to have value
getting values from database - JSP-Servlet
getting values from database  I tried the following code abc.html aaa.jsp I am not getting exceptions now... JSP code separately.If it will not display database values then try your code
Retrieve values from database using views
Retrieve values from database using views  hi......... I have a huge database so i have created views in database where i am selecting only... from that created views and display on form . I am trying to do so but its
get date picker values to a textbox
get date picker values to a textbox  I am using DatePicker to select date in a form in asp.net using c#. I need the picked data to get in to a textbox. Please help me soon
fetch values from database into text field
fetch values from database into text field  please provide the example for fetching values from database into text field of table as if i am trying following String query = "select * from LTCINFO.PERSONS"; st1
fetch values from database into text field
fetch values from database into text field  please provide the example for fetching values from database into text field of table wth edit... * from LTCINFO.PERSONS"; st1 = con.createStatement(); rs = st1.executeQuery(query
how to get the values to dropdownlist from oracle database
how to get the values to dropdownlist from oracle database   </script> </head> <body> <select name... * from countryname"); while(rs.next()){ %> <option value="<
Selecting value from autocomplete textbox using jquery in jsp
Selecting value from autocomplete textbox using jquery in jsp   hello Sir, I completed ur tutorial on autocompletion textbox from database using... not select the suggested values in the textbox,means on clicking particular field
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button...); } } }); } }   Here is a code that search the data from the database and show multiple identical rows from database on clicking search button
Advertisements
 

 

 

DMCA.com