Results 1 to 4 of 4
Thread: autocomplete using ajax
- 05-12-2011, 08:13 AM #1
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
autocomplete using ajax
Hi guys,
I am new to ajax and java technologies. From last 2 months i m working in java and other technologies.
I want to write code for autocomplete textbox in ajax using struts. i
i want fetch values frm database using struts.
in jsp page i hv to write ajax and related function of javaascript and in struts page i hv to write database connection & other related things.
Plz help me..
Its urgent!!
- 05-13-2011, 07:55 AM #2
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
i tried ajax in jsp
Hi,
i tried ajax code in jsp and struts. i m getting data frm DB but it is not displaying in textbox(displaying below textbox).
below my code in jsp page:
function showData(value){
var name1;
xmlHttp=GetXmlHttpObject();
var url="<%=request.getContextPath()%>/beforeModifyAsset.do?parameter=autoCmplete";
url=url+"&asset="+value;
xmlHttp.onreadystatechange=stateChanged ;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged() {
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
var showdata = xmlHttp.responseText;
document.getElementById("mydiv").innerHTML= showdata;
}
}
function GetXmlHttpObject(){
var xmlHttp=null;
try {
xmlHttp=new XMLHttpRequest();
}
catch (e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
<body class="background" id="bodycontent" onload="assetId()">
<html:form action="/beforeModifyAsset.do">
<br>
<center>
<span class="pageHeading"><bean:message key="LS0305" /></span>
</center>
<br>
<logic:messagesPresent>
<table width="450" border="0" cellpadding="0" cellspacing="0" align="center">
<html:messages id="error">
<tr>
<td align="center" width="95%" class="BodyTextMed">
<font color="red">
<li>
<span class="alertMsgs"><bean:write name="error" /></span>
</li>
</font>
</td>
</tr>
</html:messages>
</table>
</logic:messagesPresent>
<logic:messagesPresent message="true">
<table border="0" width="450" cellpadding="0" cellspacing="0" align="center">
<html:messages id="message" message="true">
<tr>
<td align="center" align="center">
<font color="red">
<li>
<span class="alertMsgs"><bean:write name="message" /></span>
</li>
</font>
</td>
</tr>
</html:messages>
</table>
</logic:messagesPresent>
<table width="60%" align="center" class="table">
<tr>
<td>
<table width="98%" align="center" cellSpacing=0 cellPadding=0 border=0 id="bodycontent" >
<tr>
<td align="left" class="td"> Asset Identification Number <font color="red">*</font>:</td>
<td align="left" id="asset" >
<html:text property="assetId" onkeyup="showData(this.value);"></html:text>
<div id="mydiv"></div>
</td>
</tr>
<tr>
Note: i want to display in textbox similar to google search.
plz help me.. wat to do next
- 05-13-2011, 09:48 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,466
- Rep Power
- 16
Have you debugged it?
Does it get to the server?
Does it make it into the stateChanged() method on javascript?
Come on, we can't debug this for you...
- 05-17-2011, 10:26 AM #4
Member
- Join Date
- May 2011
- Posts
- 10
- Rep Power
- 0
struts 2 ajax
struts 2 has built in ajax support with specific tags
(check them out in documentation of struts 2)
this is for JSP part
for action part you write an action which accepts parameters from request
does the processing (accessing DB, logic , formatting etc)
and writes back (using functions from ActionServletContext or even System.println) and encodes them eg JSON format.
Check the struts 2 documentaion (online or with struts package) for ajax examples i think it even has a complete ajax example but there can be variations which are not in the struts documentation but valid nevertheless.
Similar Threads
-
creating autocomplete index for multiple words (phrases)
By lrichardson in forum LuceneReplies: 2Last Post: 01-05-2011, 10:30 PM -
JList autocomplete with Vector
By nik_meback in forum AWT / SwingReplies: 0Last Post: 01-01-2011, 12:31 PM -
JList/ListDataListener Autocomplete functionality
By take2hikes in forum AWT / SwingReplies: 2Last Post: 11-09-2010, 04:56 PM -
autocomplete in text file
By Markus1 in forum New To JavaReplies: 0Last Post: 08-06-2010, 04:57 PM -
AutoComplete for jtextfield
By pinks_70986 in forum New To JavaReplies: 2Last Post: 02-12-2009, 06:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks