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

 
 


rahul
Create Listbox in JSP using AJAX control
2 Answer(s)      2 years and 8 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.

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 Pages:
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
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
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   
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
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
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
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
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
Ajax
Ajax  how to impliment ajax in registration table using jsp-servlet
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
to enter into a particular page only if the username,password and listbox value mtches
in to his page only if the username, password and the listbox value(user type) matches using "jsp".where the username,password,user type are stored in a single table...to enter into a particular page only if the username,password and listbox value
ajax
me reg this. thanks KK   Combobox box using Ajax in JSP   i...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
displaying List of records from database in a jsp using ajax
displaying List of records from database in a jsp using ajax  Sir, I...;%@page import="com.tbss.RtChannels"%><%@ taglib uri="http://java.sun.com/jsp...; //Create the Text Node with the data received
jsp and ajax
jsp and ajax  how to enable or disable textbox using radio buttons by using jsp and 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
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
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
Sitemap Ajax Tutorial
| SWT Browser | Create Tabs in Java using SWT | Create ToolTip Text in SWT... | Site Map | Business Software Services India Ajax Tutorial Section What is Ajax? | Role Of Ajax | Traditional Means of Web Application Development
Ajax
options. I want to do it using ajax. My table is CREATE TABLE HT<em>
AJAX
of that meter and should populate a table with print options. I want to do it using ajax. My table is CREATE TABLE HTNEWMETER ( ID NUMBER (10) NOT NULL, METERNO
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").  <
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
ajax  I am facing following problem, I am using ajax to get...(top,left and right) using table in jsp. On the left part i am displaying some... part. Here am using tag to display the output.Whenever user clicks on the link
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.*" %> <
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
ajax code with jsp - Ajax
ajax code with jsp  hi , Sorry for insufficient data.i m making some correction on question. I have to perform some calculation on my jsp page. i want to do it automatically (using ajax in jsp). problem is - i hv two
filter and display html table data using ajax - Ajax
filter and display html table data using ajax  Hi i am stuck up at a situation where i have a jsp page from where the control goes to the .js file calling the ajax function called retrieveURL.from here goes
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
Combo Box Using Ajax In JSP
Combo Box Using Ajax In JSP   ... to Select the Data from database using Ajax in combo box. We created two file... and Employee Name.      Step 1: Create a web page
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
Ajax code
Ajax code   I want an ajax code in jsp where selecting a listbox...); } %> For the above code, we have created two tables: 1)country: CREATE...`) ); 2)state: CREATE TABLE `state
JSP and AJAX very urgent - Ajax
JSP and AJAX very urgent  Hi Team, This is Ragavendran.R.. I have a very basic doubt in AJAX. While Using AJAX, of course, there will be tag involved in JSP page. But in my current project, I am using too many tags
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
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="<
Jsp and ajax
Jsp and ajax  Hi I am using jsp and ajax.I am retrieving...; function ajax(str){ var xmlHttp; var i; var config=document.getElementById...;select name="comboBoxMenu" id="${j}" onchange="ajax(this.value);"> <
Jsp and ajax
Jsp and ajax  Hi I am using jsp and ajax.I am retrieving...; function ajax(str){ var xmlHttp; var i; var config=document.getElementById...;select name="comboBoxMenu" id="${j}" onchange="ajax(this.value);"> <
Jsp and ajax
Jsp and ajax  Hi I am using jsp and ajax.I am retrieving...; function ajax(str){ var xmlHttp; var i; var config=document.getElementById...;select name="comboBoxMenu" id="${j}" onchange="ajax(this.value);"> <
Jsp and ajax
Jsp and ajax  Hi I am using jsp and ajax.I am retrieving...; function ajax(str){ var xmlHttp; var i; var config=document.getElementById...;select name="comboBoxMenu" id="${j}" onchange="ajax(this.value);"> <
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
JSP and AJAX- very urgent - Ajax
JSP and AJAX- very urgent  Respected Sir/Madam, I am... (Using AJAX. for ur reference, I have included the coding below: Login.html... not support AJAX!"); return; } var url="check.jsp"; url=url+"?id="+alpha
ajax in java - Ajax
ajax in java  Dear deepak sir, My page contain several control... will come "Caseno exist" Sir I am using Ajax first-time.Please help me.   Hi friend, Ajax : Asynchronous JavaScript and XML or Ajax for short
Ajax Learner - Ajax
these days. Here are the benefits of using Ajax: * Ajax can be used...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
Ajax Learner - Ajax
these days. Here are the benefits of using Ajax: * Ajax can be used.../ajax/ http://www.roseindia.net/jsp/comboSelect.shtml Thanks...Ajax Learner  Hi, This is Ziaul,I am working as Java/j2ee Developer
Login Form using Ajax
Login Form using Ajax      ... using the Ajax (DOJO).  Lets develop a login application using Ajax...;/action> Develop a Login Form Using Ajax : The GUI of the application
Table refresh with ajax - Ajax
Table refresh with ajax  I am using jsp/html in my code. Is it compulsory that i have to use a servlet to implement table refresh using ajax? Or jsp also would work? Rajatha
Ajax Chat
sources for download. With Backbase AJAX software, developers can create more... Chat This tutorial will walk you through the step in order to create an AJAX... manner. JSON AJAX Web Chat This tutorial will walk you through the steps to create
https call in AJAX - Ajax
/jsp/popup-window-using-ajax-in-jsp.shtml Hope that it will be helpful for you...https call in AJAX  Hi, I am trying to call a https URL in my AJAX script which is in my JSP. But it is not getting the reponse from the url i
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
i am getting multiple values in listbox
i am getting multiple values in listbox   hi sir, i am using msaccess 2007.my query is look like this. select distinct a.name,b.fee from table1 a,table2 b where a.stuno=b.stuno and b.recdate in(select max(recdate) from
Ajax user interface - Ajax
these all has to be do using JSP,AJAX,JDBC what exactly i needed...Ajax user interface  hello could anyone help my requirement is to design the database interaction using AJAX my requirement is a table