Hi,
I need to make a Combobox with dynamic values.
On the change of Year or Month, i want to change the values in the Week combobox.
I am able to get the values back to the screen after the Ajax call. But the combobox style class is not getting called.Its displaying as text values as below
3/1/2011-7/1/201110/1/2011-14/1/201117/1/2011-21/1/201124/1/2011-28/1/201131/1/2011-31/1/2011
Kindly help me
Below is my code :
// Ajax call method in JSP
function showWeek()
{
if(document.forms[0].reportFrequency != null && document.forms[0].reportFrequency.value =='Weekly')
{
var selectedYear = document.forms[0].selectYear.value;
var selectedMonth = document.forms[0].selectMonth.value;
var weeks = getWeek(selectedYear,selectedMonth); // this js function will get the values for the week
var xmlHttp=null;
xmlHttp=GetXmlHttpObject(xmlHttp);
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="/Web/reports/getWeeks.jsp";
url=url+"?Weeks="+weeks;
xmlHttp.onreadystatechange= stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("Report8").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest) {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
else if(window.XMLHttpRequest)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlHttp;
}
------------
// weeks has display in below div id
<div id="Report8" style="display:none">
</div>
------------------------------
getWeeks.jsp
response.setContentType("text/html");
response.setHeader("Cache-Control","no-cache");
String weeks = request.getParameter("Weeks");
String[] totalWeeks = weeks.split(":");
String combo="<html:select property=\"selectWeek\" styleClass=\"combobox\">";
for (int i=0;i<totalWeeks.length;++i)
{
System.out.println(" weeks :"+totalWeeks[i]);
combo=combo+"<option value=\""+totalWeeks[i]+"\">"+totalWeeks[i]+"</option>";
}
combo=combo+"</html:select>";
response.getWriter().write(combo);
I have copied the code from "Combo box using ajax in jsp" and created the database too .... Although the jsp shows the connected values of EMPID but when i change the selection of combo box it gives the alert message box of "Please Select Employee ID" As i dont know much about ajax please help by the Code in "Combo Box using Ajax in JSP" by rose india :-) Thanx in advance
can i do same things in a single jsp page. if i select one item in combo box according to first combo value the second combo will display value.same page as well as same table.
Could you show me that while we are using two select box.one contains states and another one contain district of those related states. By using AJAX in jsp; when we select the state, those corresponding district will be automatically loaded.
I tried and got the output too. But, my output is like just adding the fields in the jsp page into that district table data field.
in this file , how you come to know that emp_name is in "strar[1]" And emp_id is in "strar[2]" .. if i have more fields in table then how we will come to know about these ...
AutoCombodCandan January 23, 2013 at 4:14 AM
Thanks. Very Very Thanks.
Combobox not coming in JSP using AJAXBasil November 28, 2011 at 11:47 AM
Hi, I need to make a Combobox with dynamic values. On the change of Year or Month, i want to change the values in the Week combobox. I am able to get the values back to the screen after the Ajax call. But the combobox style class is not getting called.Its displaying as text values as below 3/1/2011-7/1/201110/1/2011-14/1/201117/1/2011-21/1/201124/1/2011-28/1/201131/1/2011-31/1/2011 Kindly help me Below is my code : // Ajax call method in JSP function showWeek() { if(document.forms[0].reportFrequency != null && document.forms[0].reportFrequency.value =='Weekly') { var selectedYear = document.forms[0].selectYear.value; var selectedMonth = document.forms[0].selectMonth.value; var weeks = getWeek(selectedYear,selectedMonth); // this js function will get the values for the week var xmlHttp=null; xmlHttp=GetXmlHttpObject(xmlHttp); if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="/Web/reports/getWeeks.jsp"; url=url+"?Weeks="+weeks; xmlHttp.onreadystatechange= stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } } function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("Report8").innerHTML=xmlHttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } else if(window.XMLHttpRequest) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } return xmlHttp; } ------------ // weeks has display in below div id <div id="Report8" style="display:none"> </div> ------------------------------ getWeeks.jsp response.setContentType("text/html"); response.setHeader("Cache-Control","no-cache"); String weeks = request.getParameter("Weeks"); String[] totalWeeks = weeks.split(":"); String combo="<html:select property=\"selectWeek\" styleClass=\"combobox\">"; for (int i=0;i<totalWeeks.length;++i) { System.out.println(" weeks :"+totalWeeks[i]); combo=combo+"<option value=\""+totalWeeks[i]+"\">"+totalWeeks[i]+"</option>"; } combo=combo+"</html:select>"; response.getWriter().write(combo);
need a codeMahitha January 11, 2012 at 10:24 PM
can you please help me with how to retrieve the data from the database and consolidate it based on priority using servlet?
Not Working Chirag` January 21, 2012 at 12:06 PM
i have already made table in my db and made all the necessary changes but it doesn't populate list of emp_id in combo box ............. Not Working
ajax and jspbiswaranjan March 6, 2012 at 2:36 PM
it solved my problem completely........ thnks roseindia.. i suggest to give more example on ajax
Problem related to Combo Box using ajax in jspAkash Jain March 12, 2012 at 6:25 PM
I have copied the code from "Combo box using ajax in jsp" and created the database too .... Although the jsp shows the connected values of EMPID but when i change the selection of combo box it gives the alert message box of "Please Select Employee ID" As i dont know much about ajax please help by the Code in "Combo Box using Ajax in JSP" by rose india :-) Thanx in advance
Combo BoxSourav Roy April 8, 2012 at 2:30 AM
thanks for the code
JSPAlpesh Patel April 13, 2012 at 11:15 AM
can i do same things in a single jsp page. if i select one item in combo box according to first combo value the second combo will display value.same page as well as same table.
How to do it without using scriplets?Ashish May 1, 2012 at 9:17 PM
How to do it without using scriplets?
Thanks! Not Bad to get an idea. But,NaveenRaj May 15, 2012 at 11:18 AM
Could you show me that while we are using two select box.one contains states and another one contain district of those related states. By using AJAX in jsp; when we select the state, those corresponding district will be automatically loaded. I tried and got the output too. But, my output is like just adding the fields in the jsp page into that district table data field.
confused !!!amit September 7, 2012 at 3:18 PM
in this file , how you come to know that emp_name is in "strar[1]" And emp_id is in "strar[2]" .. if i have more fields in table then how we will come to know about these ...
Post your Comment