Dobro jutro!
evo kao sto sam obecao
Code:
<html>
<head><title>Counties Beans</title>
<script type="text/javascript">
// <![CDATA[
//-----------------------------------------------------------------------------
// Define some constants.
//-----------------------------------------------------------------------------
// Define a list of Microsoft XML HTTP ProgIDs.
var XMLHTTPREQUEST_MS_PROGIDS = new Array(
"Msxml2.XMLHTTP.7.0",
"Msxml2.XMLHTTP.6.0",
"Msxml2.XMLHTTP.5.0",
"Msxml2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP"
);
// Define ready state constants.
var XMLHTTPREQUEST_READY_STATE_UNINITIALIZED = 0;
var XMLHTTPREQUEST_READY_STATE_LOADING = 1;
var XMLHTTPREQUEST_READY_STATE_LOADED = 2;
var XMLHTTPREQUEST_READY_STATE_INTERACTIVE = 3;
var XMLHTTPREQUEST_READY_STATE_COMPLETED = 4;
//-----------------------------------------------------------------------------
// Returns an XMLHttpRequest object.
//-----------------------------------------------------------------------------
function getXMLHttpRequest()
{
var httpRequest = null;
// Create the appropriate HttpRequest object for the browser.
if (window.XMLHttpRequest != null)
httpRequest = new window.XMLHttpRequest();
else if (window.ActiveXObject != null)
{
// Must be IE, find the right ActiveXObject.
var success = false;
for (var i = 0; i < XMLHTTPREQUEST_MS_PROGIDS.length && !success; i++)
{
try
{
httpRequest = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
success = true;
}
catch (ex)
{}
}
}
// Display an error if we couldn't create one.
if (httpRequest == null)
alert("Error in HttpRequest():nnCannot create an XMLHttpRequest
object.");
// Return it.
return httpRequest;
}
//-----------------------------------------------------------------------------
// This code uses an XMLHttpRequest object to look up the high school of the
// county entered by the user. That data is then used to populate the
// corresponding form fields.
//-----------------------------------------------------------------------------
var highSchoolLookup = getXMLHttpRequest();
function initiateHighSchoolLookup(event)
{
// Check for a city and state.
var county = document.MForm.COUNTY.value;
// Abort any currently active request.
highSchoolLookup.abort();
// Clear the high school drop-down list.
while (document.MForm.elements["highSchoolList"].options.length > 0)
document.MForm.elements["highSchoolList"].remove(0);
// Perform an asynchronous request to get a list of high schools for
// that state.
var url = "/servlet/coreservlets.HS_by_COUNTY?COUNTY=" +
encodeURI(county);
highSchoolLookup.onreadystatechange = highSchoolReadyStateChange;
highSchoolLookup.open("GET", url, true);
highSchoolLookup.send(null);
}
function highSchoolReadyStateChange()
{
var statusText;
// Check the ready state.
switch (highSchoolLookup.readyState)
{
case XMLHTTPREQUEST_READY_STATE_UNINITIALIZED:
statusText = "";
break;
case XMLHTTPREQUEST_READY_STATE_LOADING:
statusText = "Initialzing High School lookup...";
break;
case XMLHTTPREQUEST_READY_STATE_LOADED:
statusText = "Sending data...";
break;
case XMLHTTPREQUEST_READY_STATE_INTERACTIVE:
statusText = "Downloading data...";
break;
case XMLHTTPREQUEST_READY_STATE_COMPLETED:
// Assume no matches were found.
statusText = "No High Schools found."
// Get the XML document returned from the request and fill in the
// form fields.
try
{
var xmlDoc = highSchoolLookup.responseXML;
// Copy the county attributes from the root XML node to the
appropriate form fields.
var county = xmlDoc.documentElement.getAttribute("county");
// Get all the high school code tags returned from the request.
var els = xmlDoc.getElementsByTagName("highSchool");
// Set the status text.
statusText = els.length + " High Schools found."
// Add a dummy option to the high school drop-down list.
var option = document.createElement("OPTION");
option.text = "Select one...";
option.value = "";
try
{
document.MForm.elements["highSchoolList"].add(option, null);
}
catch(ex)
{
// For IE.
document.MForm.elements["highSchoolList"].add(option);
}
// Add an option to to the drop-down list for each high school
returned from the request.
for (var i = 0; i < els.length; i++)
{
option = document.createElement("OPTION");
option.text = option.value = els[i].firstChild.nodeValue;
try
{
document.MForm.elements["highSchoolList"].add(option, null);
document.MForm.elements["nem"].value = "NOTHING";
}
catch(ex)
{
// For IE.
document.MForm.elements["highSchoolList"].add(option);
if (document.MForm.elements["nem"].value = "EXCEPTION")
{
document.MForm.elements["nem"].value = "second time";
}
else
{
document.MForm.elements["nem"].value = "EXCEPTION";
}
}
}
// Show the drop down list and set focus on it.
document.MForm.elements["highSchoolList"].style.visibility = "";
document.MForm.HS.style.visibility = "hidden";
document.MForm.elements["highSchoolList"].focus();
}
catch (ex)
{}
break;
default:
statusText = "Unknown error.";
break;
}
// Display the status message.
setStatusText(statusText);
}
function setStatusText(text)
{
// Display the status message.
var el = document.getElementById("statusText");
if (el.firstChild == null)
el.appendChild(document.createTextNode(""));
el.firstChild.nodeValue = text;
}
</script>
</head>
<body>
<jsp:useBean id="srtCountyBean" class="coreservlets.SrtCountyBean"
scope="application" />
<jsp:useBean id="srtHsBean" class="coreservlets.SrtHsBean"
scope="application" />
<%
String[] county_nam = new String[70];
String[] county_cd = new String[70];
county_nam = srtCountyBean.getCounty_nam();
county_cd = srtCountyBean.getCounty_cd();
int counter = srtCountyBean.getCounter();
String[] hs_nam = new String[1300];
String[] hs_sfcc_cd = new String[1300];
hs_nam = srtHsBean.getHs_nam();
hs_sfcc_cd = srtHsBean.getHs_sfcc_cd();
int counter1 = srtHsBean.getCounter();
%>
<h1><%= counter1 %></h1>
<form id="MForm" name="MForm" method="get" ACTION=" ">
<INPUT TYPE=HIDDEN NAME="servNam" VALUE="hsbycounty">
<%
session.putValue("hs_sfcc_cd", hs_sfcc_cd);
session.putValue("hs_nam", hs_nam);
session.putValue("rsCounter", counter1 + "");
%>
<SELECT name="COUNTY" onchange="initiateHighSchoolLookup(event)">
<%
for(int i = 0; i < counter; i++)
{
if(county_nam[i] != null)%>
<OPTION VALUE="<%= county_cd[i] %>"><%= county_nam[i] %></OPTION>
<%}%>
</SELECT>
<br>
<div id="high_school"></div>
<select name="highSchoolList" style="visibility:hidden;"
onchange="setHsCode()"></select>
<hr>
<%
String[] test = new String[1297];
test = (String[])session.getAttribute("hs_nam");
%>
<h2><%= test[3] %></h2>
<input type="text" name="nem" id = "nem" value="nemanja">
<hr>
<CENTER>
<input type="text" name="arr">
<INPUT TYPE="SUBMIT" value="Call me...">
<div id="statusText"></div>
</CENTER>
</form>
</body>
</html>
ovo je AJAX. procitaj malo o njemu
nn