473,383 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

unable to select a value in DIV tag

12
Hi All,
I have written a AutoSuggest in jsp and am using javascript to call the strut page which calls the database and returns me the xml back.

On the html page i have a text box where i enter the name of the city and I have a DIV tag which I populate with the results.
Now my problem is that, after I get the results back I am not able to select a value from the DIV tag.

Here is the complete jsp code.

[HTML]<html>
<head>
<link style><a href="newCascadeStyleSheet.css"></a>
<script language="javascript">


/*
* Returns an new XMLHttpRequest object, or false if the browser
* doesn't support it
*/
var availableSelectList;
function newXMLHttpRequest() {

var xmlreq = false;

// Create XMLHttpRequest object in non-Microsoft browsers
if (window.XMLHttpRequest) {
xmlreq = new XMLHttpRequest();

} else if (window.ActiveXObject) {

try {
// Try to create XMLHttpRequest in later versions
// of Internet Explorer

xmlreq = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e1) {

// Failed to create required ActiveXObject

try {
// Try version supported by older versions
// of Internet Explorer

xmlreq = new ActiveXObject("Microsoft.XMLHTTP");

} catch (e2) {
// Unable to create an XMLHttpRequest by any means
xmlreq = false;
}
}
}

return xmlreq;
}

/*
* Returns a function that waits for the specified XMLHttpRequest
* to complete, then passes it XML response to the given handler function.
* req - The XMLHttpRequest whose state is changing
* responseXmlHandler - Function to pass the XML response to
*/
function getReadyStateHandler(req, responseXmlHandler) {

// Return an anonymous function that listens to the XMLHttpRequest instance
return function () {

// If the request's status is "complete"
if (req.readyState == 4) {

// Check that we received a successful response from the server
if (req.status == 200) {
// Pass the XML payload of the response to the handler function.
responseXmlHandler(req.responseXML);
} else {

// An HTTP problem has occurred
alert("HTTP error "+req.status+": "+req.statusText);
}
}
}
}

function search(searchKey) {
var form = document.forms[0];
var keyValue = document.getElementById("getCities").value;

keyValue = keyValue.replace(/^\s*|\s*$/g,"");
if (keyValue.length > 1)
{
availableSelectList = document.getElementById("searchResult");
var req = newXMLHttpRequest();
req.onreadystatechange = getReadyStateHandler(req, update);
req.open("POST","<%=request.getContextPath()%>/searchCity.do", true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send("getCities="+keyValue);
}
}


function update(cartXML)
{
var countries = cartXML.getElementsByTagName("cities")[0];
//availableSelectList.options.length = 0;
var country = countries.getElementsByTagName("city");
availableSelectList.innerHTML = '';
for (var i = 0; i < country.length ; i++)
{
ndValue = country[i].firstChild.nodeValue;
availableSelectList.innerHTML += ndValue +"<BR>\n";
}
}

</script>
</head>
<body>
<form action="/searchCity" id="searchByCityForm">
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td ><B>Event Title</b></td>
</tr>
<tr>
<td class="promo">
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td valign="top">
<input type="textbox" id="getCities" size="20" onKeyDown="search(this);" style="width:300px;" autocomplete="off" >
<div id="searchResult" name="searchResult" style="z-index: 1; left: 5px; top: 50px; width: 300px;
height: 370px; background-color:#003366; layer-background-color:#003366;"></div>

</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>[/HTML]


In the searchResult div section, which is populated from availableSelectList, I cannot do a select one value ...can anyone suggest something??

Let me know if you need more info on how the jsp page looks in the browser
Jan 3 '08 #1
3 2378
acoder
16,027 Expert Mod 8TB
How do you want to select the value? Using a dropdown select element? If so, you'll need to create it.
Jan 4 '08 #2
ashishc
12
Can you give an example code to show me ?
Jan 5 '08 #3
acoder
16,027 Expert Mod 8TB
You can create a select element with:
Expand|Select|Wrap|Line Numbers
  1. var selObj = document.createElement("select");
You'll need to append it to the body or div using appendChild. To append options to it:
Expand|Select|Wrap|Line Numbers
  1. var opt = document.createElement('option');
  2. opt.text = theTextToBeDisplayed;
  3. opt.value = theValue;
  4. try {
  5.   selObj.add(opt, null); // standards compliant way
  6. } catch(exc) {
  7.   selObj.add(opt); // for IE only
  8. }
Jan 5 '08 #4

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

Similar topics

9
by: Bob Bedford | last post by:
I've a form that use a combobox along with other fields. When the user submit the form, many tests are done. If any test fails, then I show the form again with previously entered values. My...
2
by: yankee | last post by:
Hi all, I have the following HTML code: <form> <table border=1 cellspacing=0 cellpadding=3> <tr> <td>Select a Document:</td> <td><SELECT name="type" id="type"> <OPTION
16
by: @sh | last post by:
Probably very simple, but I have a SELECT box The value of each option in the Select box will be a number, for instance... <option value="5">A test entry</option> Therefore, how do I, via an...
5
by: sensreview | last post by:
Hello, I need help in selecting a value from combo list thru one lookup table and update different table on MS access form. For eg; I have a lookup table of usernames, I need to use this...
2
by: Thad | last post by:
In the html I have a select option. I am trying to get the result of the selection(u5503_qty*5) to print after some text. I am having a problem grabbing the value of u5503_qty from the html to use...
1
by: billypit | last post by:
Hi, I am totaly new to MS Access. I have one form in MS Access in which i want that whenever i select an item from combobox then in the textbox on the same form or subform i want value from table...
3
by: viki1967 | last post by:
Hello. It's possible at this select when you select only the value BBB automatically open a web page in the window popUp ? <form method="POST" action="next.asp"> <p> <select size="1"...
4
Haitashi
by: Haitashi | last post by:
Snippet: <form> <select name="secCode" id="secCode"> <cfloop query="Request.qSecCodes"> <option value="#Request.qSecCodes.org_name#" <cfif (Request.qSecCodes.org_code EQ...
7
by: viki1967 | last post by:
Hello everyone. Try this htm page, please: http://users1.titanichost.com/MiguelRivero61/ This is the code: <html>
2
by: balajihr | last post by:
Hi All, The below query works well, but I'm unable to select * columns or selected columns from 2 tables. select FIAS_ID, ACTION_ID from CTH_ABAL_FIAS_HISTORY where ACTION_ID = 535 OR...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.