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



Home Answers Viewqa JSP-Servlet Create Listbox in JSP using AJAX control
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


rahul
Create Listbox in JSP using AJAX control
2 Answer(s)      3 years and 11 months ago
Posted in : JSP-Servlet


Hi everyone!!! I want to create an application for internal portal. here i have to create one dropdown listbox to select single elemnt using AJAX control . But i don't know anything about AJAX. In that listbox,listbox items are dictly fetched from databases tables. and i want to select only one item and save that selected in session to use that in further use.

Please, your suggestios and example codes are valuable to me. Thank you for your reply in advance.


Advertisement
View Answers

October 29, 2010 at 1:19 PM


Hello Friend,

Try the following code:

1)ajaxlist.jsp:

<%@page import="java.sql.*"%>
 <html>
 <head>  
 <script language="javascript" type="text/javascript">  
 var xmlHttp  
 var xmlHttp
 function showState(){ 
if (typeof XMLHttpRequest != "undefined"){
   xmlHttp= new XMLHttpRequest();
       }
       else if (window.ActiveXObject){
   xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
       }
if (xmlHttp==null){
    alert ("Browser does not support XMLHTTP Request")
return
} 
var url="getlist.jsp";
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
 function stateChange(){   
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
 document.getElementById("country").innerHTML=xmlHttp.responseText;  
 }   
 }
 function hello(){

var comboValue

var selIndex =document.getElementById('sel').selectedIndex;

comboValue = document.getElementById('sel').options[selIndex].value;
alert(comboValue);
}
 </script>  
 </head>  
 <body onLoad="showState();">  
 <br>  
 <form name="form">
 <div id='country'>

 </div>  
 </form>
 </body> 
 </html>

2)getlist.jsp:

<%@page language="java" import ="java.sql.*" %>  
 <%  
 String buffer="<select id='sel' onchange='hello();'>";  
 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 ResultSet rs = stmt.executeQuery("Select * from country");  
   while(rs.next()){
   buffer=buffer+"<option value='"+rs.getString(2)+"'>"+rs.getString(2)+"</option>";  
   }  
 buffer=buffer+"</select>";  
 response.getWriter().println(buffer);  
 %>

Thanks



October 29, 2010 at 2:39 PM


Thank you for your reply. But for example, we we type letter "A" in google.com brower, it gives all probable list starting from letter "A" from databases.

Like same, when i type any letter , it should show all country names in drop-down manner in list-box. And if i will not type any letter , it gives me entire list from database (stored in Mysql).

And I am not able to get selected name. I have tried using

print("code sample");

<% String abc=request.getparameter("sel"); System.out.println("selected field is :: "+abc); %>

Please, help me..Thank you for your reply in advance.



Related Tutorials/Questions & Answers:
Create Listbox in JSP using AJAX control
Create Listbox in JSP using AJAX control  Hi everyone!!! I want... listbox to select single elemnt using AJAX control . But i don't know anything about AJAX. In that listbox,listbox items are dictly fetched from databases
using jsp's....and ajax - Ajax
using jsp's....and ajax  Hi, i need code using ajax .....in a text box when i enter an alphabet i should get list of words starts with the alphabet given in the text box
Advertisements
checkbox with dropdown listbox in jsp
checkbox with dropdown listbox in jsp  i loaded the the data into the drop down listbox in jsp from access database.now i have to add a check box,if it checked means dropdownlist box carryout the data's,else it should
jsp listbox - Java Beginners
jsp listbox  thanks for your earlier post. I have one list box filled from the datebase. i want my second listbox to be filled from the database based on the selection of first list box. without refreshing my jsp page
application using AJAX and JQuery and also use JSP
application using AJAX and JQuery and also use JSP   i need create an application using AJAX and JQuery and also use JSP
Ajax using jsp
Ajax using jsp  <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import...); } %> Is there Any error...........In first Page I use ajax for displaying
ajax using jsp
ajax using jsp  <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import="java.util.StringTokenizer" %> <%@ page import="java.lang.*" %> <
datagid with paging using jsp - Ajax
datagid with paging using jsp  datagrid with paging using ajax and jsp  Hi friend, For read more information : http://www.roseindia.net/jsp/data-grid.shtml Thanks
how to create using jsp
how to create using jsp  code 1: <%@ page language="java...; <title>Create New Student</title> </head> <body> <form name="create" method="post" action="<
create using jsp
create using jsp  code 1:``<%@ page language="java" contentType..." content="text/html; charset=ISO-8859-1"> <title>Create New Student</title> </head> <body> <form name="create" method="post
Display JSP selected listbox and checkbox in xml-please help me
Display JSP selected listbox and checkbox in xml-please help me  Hi, I have three Listbox on my jsp page. I want to do following: ByDefault first... from 1st list box second will fill accordingly by database using jsp. When user
How to make session control using only JSP programming language
How to make session control using only JSP programming language  Could i do Controlling session using only JSP programming language without using anylanguage
Ajax with java(using Dojo) - JSP-Servlet
Ajax with java (using Dojo)  Hi, In In place Edit Box,when I click "save" button how can I save the data in server side i.e JSP or how can I call.... Is there a possibility for tutorial on Scriptaculous. us,for Java programmers
To create crystal report in JSP using neatbeans
To create crystal report in JSP using neatbeans  How to create crystal report in JSP using neatbeans 6.9.1.
Popup Window using Ajax In JSP
Window application using Ajax in JSP. For this, we will create the following... Popup Window using Ajax In JSP  ...: Step 1: Create a web page ("EmployeeDetail.jsp").  <
jsp and ajax
jsp and ajax  how to enable or disable textbox using radio buttons by using jsp and ajax
access image from ajax store in mysql using jsp
access image from ajax store in mysql using jsp  access image from ajax store in mysql using jsp (code to access image captured by camera and store in mysql
jsp & ajax
jsp & ajax  how to enable or disable textbox using radio buttons by using jsp and ajax? plz help me.... i m new in jsp & ajax
create childwindow - Ajax
create childwindow  i want to create child window using Ajax. Kindly help me how to create child window in my website. In this child window is used for login(user sign in option) option
how to create database and table using jsp
how to create database and table using jsp  hi frnds...., i want to create database and table in mysql using jsp.... i have an registration form(name... table using jsp code... the table name should be the name of the person
listbox and textbox validations
listbox and textbox validations  hi, any one please tell me how to set validations for listbox and textboxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  thanks for reply...) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758) org.apache.jsp.bar<em>jsp.</em>...) org.apache.jsp.bar<em>jsp.</em>jspService(bar_jsp.java:57
how to create bean using jsp and servlet
how to create bean using jsp and servlet  public class SampleBean... the following links: http://www.roseindia.net/jsp/usingbeansinjsp.shtml http://www.roseindia.net/jsp/loginbean.shtml
ajax jsp - Ajax
ajax jsp  multiple combo with ajax using jsp?  Hi friend, I am sending you a link. This link will help you. Please visit for more information. http://www.roseindia.net/jsp/comboSelect.shtml Thanks
Using Ajax
Using Ajax  Hi, How I can use Ajax in web programming? Tell me any example which using Ajax to call server side script? Thanks   Hi, Here are examples: PHP Ajax and Database First Ajax Example Getting Started
ajax and jsp code - Ajax
ajax and jsp code  can u please give me the code for retriving the data from database using ajax our requriment is if i select country name in listbox display the corresponding all the states. using jsp and ajax   
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  type Exception... org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 8 in the jsp... Foundation\Tomcat 5.0\work\Catalina\localhost\chetana\org\apache\jsp\bar_jsp.java:57
how to get popup fro servelt to jsp by using ajax........
how to get popup fro servelt to jsp by using ajax........  how to get popup fro servelt to jsp by using ajax........ I went popup in jsp page when my form submit successfully.....through servlet can any buddy give r explian how
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 generate reports from oracle database using jsp and ajax code
how to generate reports from oracle database using jsp and ajax code  Hai masters i am new to this Java world. my team leader ask me to generate sales report data from oracle database to jsp page please any one know how to do
jsp - Ajax
jsp  I'm very new in using the jsp and ajax, i have some JSP pages and i need to add some ajax features in my jsp page, for the example i need.... How can I implement this and then add this to my jsp page? please
 

 

 

DMCA.com