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



Home Answers Viewqa JSP-Servlet populating text box using jsp code
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


banajit das
populating text box using jsp code
1 Answer(s)      2 years and 9 months ago
Posted in : JSP-Servlet


Sir,

How to populate related values in a text box after selecting value from drop down list using JSP and mysql. I tried using Ajax from your example. But for some browser it does not support. Please give an example using jsp code only.


Advertisement
View Answers

January 18, 2012 at 12:21 PM


dependentDropdown.jsp:

<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<script>

function change(){
var cid=document.getElementById("book").selectedIndex;
var val = document.getElementById("book").options[cid].text;
window.location.replace("http://localhost:8080/examples/jsp/dependentDropdown.jsp?id="+cid+"&&value="+val);
}
function extract(){
var ide=document.getElementById("info").selectedIndex;
var bookname = document.getElementById("info").options[ide].text;
window.location.replace("http://localhost:8080/examples/jsp/dependentDropdown.jsp?book="+bookname);
}
</script>
<%!
Connection conn = null;
ResultSet rs =null;
Statement st=null;
String query="";

%>
<%
String value=request.getParameter("value");
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root";, "root");
st = conn.createStatement();
rs = st.executeQuery("select * from book");
%>
<select id="book" onchange="change();">
<option value="0">--Please Select--</option>
<% while(rs.next()){ %>
<option value="<%=rs.getString("books")%>"><%=rs.getString("books")%></option>
<% if(rs.getString("books").equals(value)){%>
<option value="<%=value%>" selected disabled><%=value%></option>
<%
}
}
%>
</select>
<select id="info" onchange="extract(this)">
<option value="0">--Please Select--</option>
<%
String id=request.getParameter("id");
rs=st.executeQuery("select * from bookInformation where bookid='"+id+"'");
while(rs.next()){
%>
<option value="<%=rs.getString("id")%>" ><%=rs.getString("booknames")%></option>
<%
}
%>
</select>
<%
String book=request.getParameter("book");
String author="";
String price="";
rs=st.executeQuery("select * from bookInformation where booknames='"+book+"'");
while(rs.next()){
author=rs.getString("writer");
price=rs.getString("price");
}
if((book!=null)&&(author!=null)&&(price!=null)){
%>
<table >
<tr><td>Book Name</td><td><input type="text" value="<%=book%>"></td></tr>
<tr><td>Author</td><td><input type="text" value="<%=author%>"></td></tr>
<tr><td>Price</td><td><input type="text" value="<%=price%>"></td></tr>
</table>
<%
}
%>
</body>
</html>

For the above code, we have used following database tables:

1)book

CREATE TABLE `book` (
`bookid` bigint(20) NOT NULL auto_increment,
`books` varchar(255) default NULL,
PRIMARY KEY (`bookid`)
)

2)bookinformation

CREATE TABLE `bookinformation` (
`id` bigint(255) NOT NULL auto_increment,
`bookid` int(255) default NULL,
`booknames` varchar(255) default NULL,
`writer` varchar(255) default NULL,
`Price` double default NULL,
PRIMARY KEY (`id`)
)


Related Tutorials/Questions & Answers:
populating text box using jsp code
populating text box using jsp code  Sir, How to populate related values in a text box after selecting value from drop down list using JSP and mysql.... Please give an example using jsp code only.   dependentDropdown.jsp
populating one dropdown box depending on the value of other using jsp
populating one dropdown box depending on the value of other using jsp  HI i have scenario i need to populating one dropdown box depending on the value of other using the below table country name state and city name should load
Advertisements
populating the combo box - Struts
populating the combo box  Hi I am having problem populating the combo box with a table in MS SQL Server 2005 Management Studio Express. Belo is the extract from the Struct?jsp application. Sector
Insert value of dynamic generated text box in jsp using javascript
Insert value of dynamic generated text box in jsp using javascript  hello sir , i want to generate dynamic text box at run time and i did that using... that dynamically generated text box value into database at a time without
How to get data from DB in to Text box by using Jsp & Ajax
How to get data from DB in to Text box by using Jsp & Ajax   I want to get the data from database in to text box in a jsp page by using Ajax. If I enter the letter A in the textbox it should show only those values which starts
how to display data from mysql table in text box using jsp??
how to display data from mysql table in text box using jsp??  <p>hi, i have a written a code to display data from a mysql table into txtboxes... at line: 113 in the jsp file: /Cat1.jsp The local variable v_RGPC may not have
Is it any code available for auto suggest text box using do? - Development process
Is it any code available for auto suggest text box using do?  In dojo, we are having combo box, in which auto suggestion already implemented. Like that is it we have auto suggestion for text box
Populating child dropdownlists in JSP/Servlet
Populating child dropdownlists in JSP/Servlet  Populating child dropdownlists in JSP/Servlet
add text box and select list dynamically and get its value to store it into database using jsp request parameter
add text box and select list dynamically and get its value to store it into database using jsp request parameter  its very helpful when you have only dynamically added text field but want code to retrive value of dynamically
how to create a text box using awt
how to create a text box using awt  give an example how creat multi buttons & text boxes
JSP Text Box properties. - JSP-Servlet
JSP Text Box properties.  How do I restrict a text box created in JSP... any such in JSP. please let me know how to do it..  Hi Friend, Try the following code: function isNumber(){ if(/^-?\d+(\.\d+)?$/.test
Auto Complete Text Box - JSP-Servlet
Auto Complete Text Box  Please help me in Aotocomplete text box code. I m a java programmer. I m working on jsp tech. please give me the code for Autocomplete text box in which the values will generate from database table
reading data from a text box with the same name using servlets - JSP-Servlet
reading data from a text box with the same name using servlets  ... like a= b= c= using servlet i want to print all the values from each text box? is it possible.this question i faced in an interview. kindly reply
Display current date in text box in JSP using javascript
Display current date in text box in JSP using javascript In this section you will learn how to display current date in text box using JavaScript.For... in the textbox. Here is the code: <html> <script>
create text box by clicking button and submittong text in text box using submit
create text box by clicking button and submittong text in text box using... is created. and i want to do that when i enter the text input in text box and when i... box in SOP). i also want the text box should generate in front of NEW button
Automatically display in text box - JSP-Servlet
Automatically display in text box  Dear Deepak Sir, When i enter some text in text box.That corresponding value in database,the value display in another text box using ajax. Thanks & Regards, VijayaBabu.M
Auto Complete Text Box - JSP-Servlet
Auto Complete Text Box - JSP-Servlet  Auto Complete Text Box Please help me in Aotocomplete text box code. I m a java programmer. I m working on jsp tech. please give me the code for Autocomplete text box in which the values
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
retriving data from sql server using jsp code and placing them in text fields of html code
retriving data from sql server using jsp code and placing them in text fields... server 2008 using a jsp file and place the values in the text fields of a html file..." and address "abbanna colony" in those text fields using a query "select * from
a jsp code for creating a text file
a jsp code for creating a text file  Hello,i need jsp code for creating a new text file for each user, when they login in to the website for creating a new data file. So i need a jsp code for following options. when user login
How to Validate dynamically created text box in HTML using Javascript
How to Validate dynamically created text box in HTML using Javascript  Here is the HTML code to create text boxes dynamically. It works properly.... And also how to validate the text boxes created dynamically. <html>
To Retain the values entered in the text box after submit in jsp page
To Retain the values entered in the text box after submit in jsp page   i am working on a jsp pge which has many text boxes and one dynamic drop down. The functionality is when user enters comma separated values in those text
Text box Checking
Text box Checking  I want to Write only the word A-Z in a text box What is the code
auto complete text box - Ajax
auto complete text box  How to create auto complete text box in jsp using ajax technology ? plz giv me steps wise code
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  For example, In Employee.jsp form, When i click employee id value in combo box ,the related employee name will be displayed in text field
populating textbox value from the database using onchange function,
populating textbox value from the database using onchange function,  hi, Everyone I have a problem regarding poulatinng the value in textbox after selecting from dropdownlist. i have a form in jsp n I created the dropdown list
I am getting Undefined in Text Box Very Urgent - JSP-Servlet
I am getting Undefined in Text Box Very Urgent  Respected Sir/Madam... the value "Undefined" in Emp ID text box which is present in the main page.. Here's... application. Read for more information. http://www.roseindia.net/jsp/popup-window
text to speech code in jsp - Java Magazine
text to speech code in jsp  Is their any code in jsp for text to speech i.e when i enter text in text area and press submit button , the text i entered should come in voice as output
tree using jsp code
tree using jsp code  i want to draw a tree structure of a family hierarchy using jsp code
How to populate text fields using php code?
How to populate text fields using php code?  How could I use php to populate text fields by selecting a name of a business from dropdown list? Those text fields that will be populated by information in regards its company name
J2ME Text Box Example
J2ME Text Box Example       This application illustrates how to create the text box using TextBox class. The TextBox class is a Screen that allows the user to enter and edit text
Advertisements
 

 

 

DMCA.com