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

 
 


niharika gupta
Autopopulate values into textbox from database on pressing tab or on clicking
2 Answer(s)      a year and 10 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.

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 Pages:
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
Asp.net with C#
Asp.net with C#  Autopopulate values into textbox from database on pressing tab
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
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. <
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
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
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
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 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
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
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
Database values in JComboBox
Database values in JComboBox In this section, you will learn how to display values in JComboBox from database. For this, we have allowed the user to enter any character as a key in the textbox .Based on this key value, the results from
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
Retrieve data by clicking a link
Retrieve data by clicking a link  In a page there are 5 links.Every link has a hidden value. According to that hidden value data should be retrieved from the database and data should be displayed in a new page.How to do it?Please
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
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
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
How to read and retrieve jtable row values into jtextfield on clicking at particular row ...
How to read and retrieve jtable row values into jtextfield on clicking... application in which i have to display database records in jtable .now I want to read all the values of particular row at which mouse is clicked. and display
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
dropdown vlaue changes based on input given in textbox uisng AJAX
dropdown vlaue changes based on input given in textbox uisng AJAX  hi, In my app i need one textbox based on textbox data, values in dropdown list have to change and dropdown data retreive data from database thanks KK
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
Autocomplete textbox with database in jsp and follow the MVC model
Autocomplete textbox with database in jsp and follow the MVC model  i have one problem in my project i try to generate the autocomplete textbox with database mysql follow MVC Model but it not perform. So please Help me sir
Sql Server 2008 with textbox
textbox in a form using vb by visual studio 2010 but its always catch an error [Cannot open database "4" requested by the login. The login failed. Login failed... = "INSERT INTO Table1 (A , B) VALUES ('" + Asd + "','" + Lays + "') " cmd = New
how to display the database values in pdf format
how to display the database values in pdf format   in struts how to display the values in pdf format when clicking a button in jsp page   ...(); ResultSet rs=st.executeQuery("Select * from data"); while(rs.next
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
Dynamically hide textbox
Dynamically hide textbox  I have a drop down(combo box) with 2 values (reference and file).When refrence is selected from the drop down the components of file(that is displayed when file is selected) should get hidden dynamically
storing details in database on clicking submit button - JSP-Servlet
storing details in database on clicking submit button  I am using JSP... database on clicking submit button. I am unable to do this.Can u tell me how to code......Tell me where an what code should I write to store the values in data base table
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
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
send multiple textbox vaues in to an jsp form to store them in a DB table
values in to an jsp file with additional values to store those values in to an database table. Please help me...... looking forward to hear from you...send multiple textbox vaues in to an jsp form to store them in a DB table 
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
HOW TO DISPLAY ID IN TEXTBOX BASED ON COMBOBOX SELECTION IN A SAME PAGE
is how to get Roleid in textbox when i select Role_name from combobox in a same...HOW TO DISPLAY ID IN TEXTBOX BASED ON COMBOBOX SELECTION IN A SAME PAGE ... Roleid and Role_name. and values are Roleid Role_name 1
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
To retrive data from database - Struts
To retrive data from database  How to get values ,when i select a select box in jsp and has to get values in textbox automatically from database? eg... come to jsp page automatically from database
Ajax drop down and textbox
menu consisting of options 1,2,3. When the user select any option from...;And one more thing how to insert to the database dynamically
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
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
Displaying database values in pdf format
Displaying database values in pdf format  Hi All, I am... the form the values are stored in database,the database name is registration... database values should be shown as pdf or excel format. Thanks in advance
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="<
Delete a row from database by id
Delete a row from database by id  I m creating a small application... all the values are added in to database and page is redirected to a new page...) for "DELETE" AND "UPDATE". On clicking delete which is hyper link that particular row
Javascript generate textbox
of textboxes. On clicking the button with respect to each textbox, it will give...Javascript generate textbox In this tutorial, you will learn how to generate a textbox on button click using javascript. Here is a javascript example
Arraylist from row values
Arraylist from row values  Hello, can anyone please help on how to make an arraylist from the row values of a particular column from a database...("select * from employee"); ArrayList<String> list=new ArrayList<
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
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
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
display all the values on next page
in the database through textboxes and dropboxes, when i am clicking on submit button those values are inserting in the database and i am moving on another page after... when i return on first page it should display my selected values in textbox

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.