473,785 Members | 2,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ajax, JSP, object expected, linked drop down list

nmm32
9 New Member
I am trying to use Ajax with JSP to populate a 2nd drop down list based on the chosen option of the first one. I am getting the error "Object Expected" on the line 13-14 of the HTML:

Expand|Select|Wrap|Line Numbers
  1.  <script language="javascript">
  2.  
  3.  // Global Variable for XmlHttp Request Object   
  4.       var xmlhttp;
  5.       var yearDDL;
  6.  
  7. function handleOnChangepType(ddl)
  8. {
  9.   //index y texto del item seleccionado
  10.   var ddlIndex = ddl.selectedIndex;
  11.   var chosenType = ddl[ddlIndex].text;
  12.   var frmSelect = document.forms["frmSelect"];
  13.   var frmSelectElem = frmSelect.elements;   
  14.   yearDDL  = frmSelectElem["year"];  
  15.  
  16.   if ( chosenType != "Select Type")
  17.   { 
  18.               xmlhttp = null 
  19.             // code for initializing XmlHttpRequest Object On Browsers like  Mozilla, etc. 
  20.             if (window.XMLHttpRequest){  
  21.                  xmlhttp = new XMLHttpRequest()                   
  22.             } 
  23.             // code for initializing XmlHttpRequest Object On Browsers like IE
  24.  
  25.            else if (window.ActiveXObject) {  
  26.                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")           
  27.            }
  28.  
  29.            if (xmlhttp != null){
  30.                 // Setting the Servlet url to get XmlData
  31.                url = "searchAvailableYears.jsp?pType=" + chosenType;               
  32.                // Course of Action That Should be Made if their is a change in XmlHttpRequest Object ReadyState NOTE : it is 4 when it has got request from CGI
  33.                xmlhttp.onreadystatechange = handleHttpResponse;
  34.  
  35.                // Open the Request by passing Type of Request & CGI URL 
  36.                xmlhttp.open("GET",url,true);
  37.  
  38.                // Sending URL Encoded Data
  39.                xmlhttp.send(null);               
  40.            }
  41.            else{  
  42.              // Only Broswers like IE 5.0,Mozilla & all other browser which support XML data Supports AJAX Technology
  43.              // In the Below case it looks as if the browser is not compatiable
  44.               alert("Your browser does not support XMLHTTP.")              
  45.            }  //else        
  46.  
  47.            }  //if chosen
  48.  
  49.     }  //fucntion
  50.  
  51.     //----------------------------
  52.  
  53.       /* Used for verifing right ReadyState & Status of XmlHttpRequest Object returns true if it is verified */
  54.       function verifyReadyState(obj){
  55.  
  56.          // As Said above if XmlHttp.ReadyState == 4 then the Page Has got Response from WebServer
  57.           if(obj.readyState == 4){
  58.  
  59.            // Similarly if XmlHttp.status == 200 it means that we have got a Valid response from the WebServer
  60.             if(obj.status == 200){                
  61.  
  62.                 return true
  63.              }
  64.              else{
  65.  
  66.                 alert("Problem retrieving XML data")
  67.              }             
  68.           }          
  69.       }
  70. //-----------------------------------
  71. function handleHttpResponse() 
  72. {
  73.    if(verifyReadyState(xmlhttp) == true)
  74.    {
  75.  
  76.    // Building a DOM parser from Response Object
  77.    var x = xmlhttp.responseXML.getElementsByTagName("option");
  78.  
  79.    // Checking for the Root Node Tag
  80.              // var x = response.split("|")
  81.             //  var tex
  82.              // var optn
  83.  
  84.    yearDDL.length = 1;
  85.    yearDDL.length = x.length;
  86.    for (o=1; o < x.length; o++)
  87.    {
  88.      yearDDL[o].text = x[o];
  89.    }
  90.   else
  91.   {
  92.    alert("Cannot handle the Ajax call.");
  93.   }
  94. } //if
  95. }//function
  96. </script>
-------------------------------

HTML part:

[HTML]<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link rel="stylesheet " type="text/css" href="style.css ">
</head>
<body bgcolor="ivory" >
<form name="frmSelect ">
<p><strong><u>T est</u></strong></p>
<p><hr color="orange"> </p>
<table border="0">
<tr><td><strong >Type</strong></td>
<td>
<select name="pType" onchange="handl eOnChangepType( this);">

<option>Selec t Type</option>
<%
String allDir[] = {"A", "B", "C"}; //dirs con los que se trabajará

for(int i=0; i<3; i++)
{
File dir = new File("C:/apache-tomcat-6.0.10/webapps/ROOT/p1/db/" + allDir[i] ); //(fenomenos A, B, C)


if (dir.exists() && dir.isDirectory ())
{
%>
<option><%=allD ir[i]%></option>
<%

} //if
} //for
%>

</select >
</td></tr>

<td><strong>Yea r</strong></td>
<td>


<select name="year">
<option></option>
</select>

</td>
</tr>
<tr><td><strong >Day</strong></td>
<td>


<select name="day">
<option></option>
</select>

</td></tr>
<tr><td><strong >Times available<br>fo r the selected day</strong></td>
<td>
<select name="range1">
<option></option>
</select>
</td>

</tr>
</td></tr>
</table>

</body>

</html>[/HTML]---------------------------------------------------------

The JSP code:
Expand|Select|Wrap|Line Numbers
  1. <%@ page contentType="text/html" %>
  2. <%@page import="java.io.*,
  3.                 javax.servlet.*,
  4.                 javax.servlet.http.*,
  5.                 java.lang.*,
  6.                 java.util.*
  7.                 "
  8. %>
  9.  
  10.  
  11. <%
  12.  
  13. String pType = request.getParameter("pType");
  14. response.setContentType("text/xml");    
  15. response.setHeader("Cache-Control", "no-cache");
  16. if (pType == "A" || pType == "B" || pType == "C")
  17.  
  18. {
  19.     File dir = new File("C:/apache-tomcat-6.0.10/webapps/ROOT/p1/db/" + pType); 
  20.     String[] allFilesInDir = dir.list();
  21.     ArrayList years = new ArrayList();
  22.     String option;
  23.  
  24.     for(int i=0; i < allFilesInDir.length; i++)
  25.     {
  26.      if (allFilesInDir[i].substring(0,0) == "d" || allFilesInDir[i].substring(0,0) == "D")
  27.      {
  28.        years.add(allFilesInDir[i].substring(1,4));       
  29.        option = "<option>" + years.get(i) + "</option>";
  30.       response.getWriter().write(option);     
  31.  
  32.      }
  33.  
  34.     }
  35.   } 
  36.   else
  37.   {
  38.    response.getWriter().write("<option>THIS IS A TEST</option>");
  39.    }
  40.  
  41. %>
Any suggestions will be very much appreciated!

Thank you!
Jun 14 '07 #1
1 8373
acoder
16,027 Recognized Expert Moderator MVP
Is this in all browsers? What do you see in the error console?
Jun 15 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

31
3167
by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is the same "prototype.js" that is not well-liked around here? If so, do you know if Ajax.NET can be used without prototype.js? -- "The most convoluted explanation that fits all of the made-up facts is the most likely to be believed by conspiracy theorists. Fitting the
0
1832
by: arunprabu | last post by:
Hi, I have a problecm with the AJAX request in my webpage. I have some filters on top of the page. I have a submit button and an empty div below the filters. Some of the filters have ajax requests to update the content within the filters. For example, I have 2 drop downs, one for state and another for country. When I select a country in the country drop down, an ajax request is sent to fetch appropriate list of states and updates the
1
16513
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX - microlink pattern tutorial : A microlink is a link that opens up
1
2474
by: AndiSmith | last post by:
Hi guys, I wondered if anyone could help me with this problem, or even shed some light on the direction I need to take to resolve it? I'm using .NET 2.0 (C# flavor) to build a large user-based website. I've created an AJAX based user control, which is dynamically placed on a page (once, or multiple times) if the user has the correct permissions to receive it. It contains two drop down lists - employee value and partner value; and a...
1
1856
by: Boris Twila | last post by:
I just want to have 1 drop down list fill the other drop down list without a round trip. Is there some really simple ajax thing i can copy and use, or is it a big deal do i habe to install an ajax server or something
6
3087
by: Rob Meade | last post by:
Hi all, Looking for a bit of help if possible. For about 2 weeks now I've been investigating the best way to populate related drop down menus, and have their values pre-populated again if the user clicks back with their selected options still selected - and I'm getting to the point where I might just popup a big window, perhaps with some flash in it and say "dont be lazy, select em again you great big freak of nature" because I am...
0
3171
by: jrnail23 | last post by:
I have a user control which contains an UpdatePanel, which contains a MultiView inside, with a GridView in one of the views. In my GridView, I have a ButtonField which is supposed to trigger a server-side operation, using the RowCommand functionality. In IE, this all works great, but in Firefox (v2.0.0.6), clicking the above mentioned ButtonField fires off two similar AJAX requests, which is causing errors in my server-side code. ...
2
1862
by: Johnson | last post by:
While I have done a substantial amount of ASP.NET programming, I have only dabbled with AJAX (update panels and a 3rd party JSON setup - jayrock - that directly updates the DOM). In any case, I'm considering offering Web pages both to browsers that support AJAX and to those that do not support AJAX. Questions: 1. In general, should I look to offer two versions of each page - one for AJAX clients and the other for "non AJAX-supporting"...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.