Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

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

843838Jun 13 2007 — edited Jun 16 2007
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 the HTML part... I didn't pasted everything:
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body bgcolor="ivory">
<form name="frmSelect">

<p><strong><u>Test</u></strong></p>
<p><hr color="orange"></p>

	<table border="0">
	<tr><td><strong>Type</strong></td>	
	<td>	
	
	<select name="pType" onchange="handleOnChangepType(this);">	
	<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%></option> 	
<%

} //if
} //for
%>

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

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


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

</td>
</tr>
(.....)
</table>

</body>

</html>
//-------------------------------------------------------

The Javascript 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(
{ [b]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 the JSP 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.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 be very very appreciated!


Thank you!,
MMS
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 11 2007
Added on Jun 13 2007
2 comments
91 views