AJAX, array, multiple items, Option, Select, drop-down list

Hello everyone:

I am now trying with AJAX because in my last post ( http://forum.java.sun.com/thread.jspa?threadID=5182787&messageID=9712775) I had a messy "fuzzy logic".

I am not getting any results in the 2nd drop-down box, and I am getting this error:

Error: uncaught exception: Permission denied to call method XMLHttpRequest.open

In the page http://code.jalenack.com/categories/ajax/ they tell something about that error... but I do not understand well because I am working all in the same server. It is related to "requests off-domain".

....and I am starting to wonder again if this will ever work...

Ok below is theHTML part... I didn't pasted everything:

<html>

<head>

<title></title>

<link rel="stylesheet" type="text/css" href="style.css">

</head>

<body bgcolor="ivory">

[b]<form name="frmSelect">[/b]

<strong><u>Test</u></strong>

<hr color="orange">

<table border="0">

<tr><td><strong>Type</strong></td>

<td>

<[b]select name="pType" onchange="handleOnChangepType(this);">[/b]

<option>Select Type</option>

<%

String allDir[] ={"A","B","C"};

//ALL THIS IS WORKING FINE!

for(int i=0; i<3; i++)

{

File dir =new File("C:/apache-tomcat-6.0.10/webapps/ROOT/p1/db/" + allDir[i] );

if (dir.exists() && dir.isDirectory())

{

%>

<option><%=allDir[i]%></option>

<%

}//if

}//for

%>

</select >

</td></tr>

<td><strong>Year</strong></td>

<td>

<select name="year">

<option></option>

</select>

</td>

</tr>

(.....)

</table>

</body>

</html>

//-

TheJavascript functions I am using:

function handleOnChangepType(ddl)

{

var ddlIndex = ddl.selectedIndex;

var ddlTxt = ddl[ddlIndex].text;

var frmSelect = document.forms["frmSelect"];

var frmSelectElem = frmSelect.elements;

var year = frmSelectElem["year"];

var chosenType = ddlTxt;

if ( chosenType != "Select Type")

{

Http.get(

{url: "C:/apache-tomcat-6.0.10/webapps/ROOT/p1/scodes/searchAvailableYears.jsp?pType=" + chosenType,

callback: fillYear,

cache: Http.Cache.Get},

[year]); }

}

function fillYear(XMLResponse, year)

{

if (XMLResponse.status == Http.Status.OK)

{

var theOptions = XMLResponse.responseXML.getElementsByTagName("option");

alert(theOptions.length);

year.length = theOptions.length;

for (o=1; o < theOptions.length; o++)

{

year[o].text = theOptions[o];

}

}

else

{

alert(XMLResponse.status);

alert(" Error ");

}

}

//--

....And finally theJSP page that receives the parameters and it is expected to respond with the items that will be shown in the 2nd drop-down list........

<%@ page contentType="text/html" %>

<%@page import="java.io.*, javax.servlet.*,javax.servlet.http.*,java.lang.*,java.util.*"

%>

<%

String pType = request.getParameter("pType");

if (pType ==null)

{pType="A";}

else

{

File dir =new File("C:/apache-tomcat-6.0.10/webapps/ROOT/p1/db/" + pType);

String[] allFilesInDir = dir.list();

String[] years;

String option;

response.setContentType("text/xml");

response.setHeader("Cache-Control","no-cache");

for(int i=0; i < allFilesInDir.length; i++)

{

if (allFilesInDir[i].substring(0,0) =="d" || allFilesInDir[i].substring(0,0) =="D")

{

years[i] = allFilesInDir[i].substring(1,4);

option ="<option>" + years[i] +"</option>";

response.getWriter().write(option);

}

else

{

response.getWriter().write("<option>THIS IS A TEST</option>");

}

}

}

%>

I took examples from: http://www.webmonkey.com/webmonkey/06/15/index3a_page2.html?tw=authoring

Any help will bevery very appreciated!

Thank you!,

MMS

[6138 byte] By [tofuwithcoffeea] at [2007-11-27 7:36:17]
# 1
What browser are you using? xmlHttpReq = new XMLHttpRequest();xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); Javascript error also may cause this bug.
skp71a at 2007-7-12 19:16:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Firefox and IE.

For the script I am using...

"A wrapper for XmlHttpRequest that supports forced caching on FireFox and forced non-caching on IE."

......found in http://adamv.com/dev/javascript/files/request.js

http://www.webmonkey.com/webmonkey/06/15/index3a_page2.html?tw=authoring

It gives me that error on FireFox, however in IE I am getting "Http undefined".......

I will check this and reply later..

... help is always kindly received...

-

If I solve this problem I will post the whole code here....

tofuwithcoffeea at 2007-7-12 19:16:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...