Categories | Question details Back To List | ||
I have 2 list box in Jsp Page. I have 2 list box in Jsp Page.The first contain All tourname. > Second list box has to populate values based on tournames selected from > first listbox.(Say second list box has to contain departuredates). I want to code it using javascript to load the departure dates using script. created a function in a class to get the date. public String[][] getDepartureDates(String tourNum,String tourCode,String tourName){ //sql='SELECT dept_date FROM ts_tour WHERE tour_num=''+tourNum+'' and trim(tour_code)=''+tourCode+'' and TRIM(tour_name) =''+tourName.trim()+'' and (tour_num,tour_code,dept_date) NOT IN (SELECT bpchar(str_tour_numb),bpchar(trim(str_tour_code)),dat_tour_date as dept_date FROM tsp_dpst_mgmt WHERE str_tour_numb=''+tourNum+'' AND TRIM(str_tour_code)=''+tourCode+'')'; tourNum=tourNum==null?'':tourNum.trim(); tourCode=tourCode==null?'':tourCode.trim(); tourName=tourName==null?'':tourName.trim(); System.out.println('tourNum'+tourNum); System.out.println('tourCode'+tourCode); System.out.println('tourName'+tourName); String result[][]=null; // String sql='SELECT dept_date FROM ts_tour WHERE tour_num=''+tourNum+'' and trim(tour_code)=''+tourCode+'' and (tour_num,tour_code,dept_date) NOT IN (SELECT bpchar(str_tour_numb),bpchar(trim(str_tour_code)),dat_tour_date as dept_date FROM tsp_dpst_mgmt WHERE str_tour_numb=''+tourNum+'' AND TRIM(str_tour_code)=''+tourCode+'')'; String sql ='SELECT a.dept_date FROM ts_tour as a LEFT OUTER JOIN inventory as c ON a.dept_date = c.tour_Date and a.tour_num=c.tour_num and c.type = 'S' and a.tour_code = c.tour_code, template_tour as b WHERE a.tour_num=''+tourNum+'' and trim(a.tour_code)=''+tourCode+'' and a.dept_date >= current_date-30 and a.tour_num=b.tour_num ORDER BY a.dept_date asc'; System.out.println(' sql:::::::::::::getDepartureDates() : '+sql); try{ result=dbcon.getResult(sql); }catch(Exception e){ } return result; } while executing values are null... my jsp page tsptourdesc.jsp <%@ page language='java' import='java.util.*' %> <%@ taglib uri='/WEB-INF/struts.tld' prefix='struts' %> <%@ taglib uri='/WEB-INF/struts-form.tld' prefix='form' %> <%@ taglib uri='/WEB-INF/struts-bean.tld' prefix='bean' %> <%@ taglib uri='/WEB-INF/struts-logic.tld' prefix='logic' %> <%@ taglib uri='/WEB-INF/struts-html.tld' prefix='html' %> <% String scope=request.getParameter('scope'); String accountId=(String)session.getValue('accountId'); if(accountId ==null){ response.sendRedirect(request.getContextPath()+'/login.jsp'); } accountId =accountId ==null?'':accountId.trim(); String clientName=(String)session.getValue('companydb'); clientName=clientName==null?'':clientName.trim(); String appPath=(String)session.getValue('applicationpath'); appPath=appPath==null?'':appPath.trim(); String buildMode=(String)session.getValue('buildmode'); String buildStatus=(String)session.getValue('buildstatus'); String tourMessage=(String)session.getValue('message'); String acctComp = (String)session.getValue('usercompany'); acctComp=acctComp==null?'':acctComp.trim(); %> <head> <jsp:useBean id='dataPool' class='com.centaur.tcp.TCPPool' /> <jsp:setProperty name='dataPool' property='database' value='<%=clientName%>'/> <jsp:setProperty name='dataPool' property='accountid' value='<%=accountId%>'/> <jsp:setProperty name='dataPool' property='usercomp' value='<%=acctComp%>'/> <link rel='stylesheet' href='<%=appPath%>/style.css' type='text/css'> <script language='JavaScript' src='<%=appPath%>/scripts/Calendar.js'> </script> <script> var tspScope='<%=scope%>'; function validate(){ var frm=document.forms[0]; if(frm.tourNum.value=='' && frm.tourDate.value=='' && frm.tourCode.value==''){ alert('Please enter any criteria'); frm.tourNum.focus(); }else { document.forms[0].submit(); } } //function to check tour code value var flag=0; function tournumadjust(ths) { flag=0; chkChar(ths); var zeros = 0; var tno=''; if((ths.value.length<6)&&(ths.value.length>0)&& (flag==0)){ zeros=6-(ths.value.length); for(var i=0;i<zeros;i++) tno+='0'; tno+=ths.value; ths.value=tno; flag=0; } } function chkChar(ths) { var content=ths.value; for(i=0;i<content.length;i++) { if((content.charAt(i)>='0')&&(content.charAt(i)<='9')&& (flag==0)) {flag=0; continue; } else { alert('Please enter only numeric values'); ths.select(); flag=1; break; } } } function goback(){ history.back(); } function tourdepartureView(){ if(document.forms[0].tourNum.value==''){ alert(' Please Select a Tour '); document.forms[0].tourNum.focus(); return false } tourNum=document.forms[0].tourNum.value; tourCode=document.forms[0].tourCode.value; document.location.href='<%=appPath%>/tsp/tspTourSearchResultTemp.jsp?scope=build&tourNum='+tourNum+'&tourCode='+tourCode; } function deptDate(value) { alert('insidedept Date'); alert('value'+value); } </script> </head> <body bgcolor='#FFFFFF' > <form action='<%=appPath%>/tspTourSearch.do' method='GET'> <table width='100%' border='0' cellspacing='1' cellpadding='0'> <tr><td class=message> <%if(buildStatus!=null && buildMode!=null && buildMode.equals('add')){%> <center><font class='message'><%=buildStatus%></font></center> <% session.removeAttribute('buildstatus'); session.removeAttribute('buildmode'); }if(buildStatus!=null && buildMode!=null && buildMode.equals('modify')){ %> <center><font class='message'><%=buildStatus%></font></center> <% session.removeAttribute('buildstatus'); session.removeAttribute('buildmode'); }if(tourMessage!=null){ %> <center><font class='message'><%=tourMessage%></font></center> <% session.removeAttribute('message'); } %> </td> </tr> </table> <% String[][] sActTour = null; String[][] sDateTour = null; String tour = ''; String tourNum = ''; String tourCode = ''; String tourNo = ''; String tourCd = ''; String tourName = ''; String tournameSelect=''; try{ if('build'.equals(scope)){ sActTour=dataPool.getTCPTourList(); sDateTour=dataPool.getDepartureDates(tourNum,tourCode,tourName); }else{ sActTour=dataPool.getAllTours(); sDateTour=dataPool.getDepartureDates(tourNum,tourCode,tourName); } }catch(Exception e){ out.print('Exception in display tour : '+e); } %> <table width='100%' border='0' cellspacing='1' cellpadding='0'> <tr> <td height='20' align='left' colspan='2' class='smallhead1'>Save As Another Tour</td> </tr> <tr class='trow1'> <td class='trow' width='40%'>Select Tour Name</td> <td width='60%'><select name='trName' size='1' Class='lists' value='<%=tournameSelect%> ' onchange='javascript:deptDate(value);'> <option value=''><Select any Tour></option> <%try{ if('build'.equals(scope)){ for(int i=0; i<sActTour.length;i++){ tourNo = sActTour[i][0]; tourNo=tourNo==null?'':tourNo.trim(); } }else{ for(int i=0;i<sActTour.length;i++) { tourNo=(String)sActTour[i][0]; tourNo=tourNo==null?'':tourNo.trim(); tourCd=(String)sActTour[i][1]; tourCd=tourCd==null?'':tourCd.trim(); tourName=(String)sActTour[i][2]; tourName=tourName==null?'':tourName.trim(); if(!''.equals(tourName)){ tournameSelect=tourName; } if(!''.equals(tourNo)){ tournameSelect=tournameSelect+' | '+tourNo; } if(!''.equals(tourCd)){ tournameSelect=tournameSelect+' | '+tourCd; } out.println('<option value=''+tourNo+'-'+tourCd+''>'+tournameSelect+'</option>'); } } }catch(Exception ex){ out.print('exception in assign : '+ex); } %> </select> </td> </tr> <tr class='trow1'> <td class='trow' width='40%'>Select DepartureDate</td> <td width='60%'><select name='Date' size='1' Class='lists' > <option value=''><Select any Date></option> <%try{ if('build'.equals(scope)){ for(int i=0; i<sActTour.length;i++){ tourNo = sActTour[i][0]; tourNo=tourNo==null?'':tourNo.trim(); tourName = sActTour[i][1]; tourName=tourName==null?'':tourName.trim(); tourCd = sActTour[i][2]; tourCd=tourCd==null?'':tourCd.trim(); if(!''.equals(tourName)){ tournameSelect=tourName; } if(!''.equals(tourNo)){ tournameSelect=tournameSelect+' | '+tourNo; } if(!''.equals(tourCd)){ tournameSelect=tournameSelect+' | '+tourCd; } //tournameSelect=tournameSelect.replace('&','`'); out.println('<OPTION value='+tourNo+'-'+tourCd+'>'+tournameSelect+'</option>'); } }else{ for(int i=0;i<sActTour.length;i++) { tourNo=(String)sActTour[i][0]; tourNo=tourNo==null?'':tourNo.trim(); tourCd=(String)sActTour[i][1]; tourCd=tourCd==null?'':tourCd.trim(); tourName=(String)sActTour[i][2]; tourName=tourName==null?'':tourName.trim(); if(!''.equals(tourName)){ tournameSelect=tourName; } if(!''.equals(tourNo)){ tournameSelect=tournameSelect+' | '+tourNo; } if(!''.equals(tourCd)){ tournameSelect=tournameSelect+' | '+tourCd; } out.println('<option value=''+tourNo+'-'+tourCd+''>'+tournameSelect+'</option>'); } } }catch(Exception ex){ out.print('exception in assign : '+ex); } %> </select> </td> </tr> <tr> <td colspan='2' align='right' class='theading'> <input type=button class=lists value= 'Search' onClick='javascript:validate()'> <input type=button class=lists value= ' Back ' onClick='javascript:location.href='<%=appPath%>/tsp/tspMenu.jsp';'> </td> </tr> </table> <input type='hidden' name='tourName' value='<%=tournameSelect%>'> <input type='hidden' name='scope' value='<%=scope%>'> <input type='hidden' name='database' value='<%=clientName%>' > <input type='hidden' name='userid' value='<%=accountId%>' > <input type='hidden' name='tourNum' value='<%=tourNo%>' > <input type='hidden' name='tourCode' value='<%=tourCd%>' > </form> </body> please suggest an idea Answer posted by Support on Feb 26, 2008 06:11 In case of using dhtmlxcombo - you can attach onChange event to first combo and just call loadXML with necessary params for second combo ( or fill it from available js data ) |