GeeCON Prague 2014*
The moose likes Struts and the fly likes autocomplete using ajax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "autocomplete using ajax" Watch "autocomplete using ajax" New topic
Author

autocomplete using ajax

shashi bhushans
Greenhorn

Joined: May 12, 2011
Posts: 17
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.
Please give scr code..
Its urgent!!
Struts Master
Greenhorn

Joined: May 12, 2011
Posts: 1
Hi Sashi,

http://firstpartners.net/whitepapers/Sprinkle_some_Ajax_Magic_into_your_Struts_application.pdf

Try out this link. Should solve your problem. Let me know if you face any issue.

Thanks
Amit
http://www.ansmap.com
shashi bhushans
Greenhorn

Joined: May 12, 2011
Posts: 17
Hi,o
i tried ajax code in jsp and struts. i m getting data from 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.
please help me.. what to do next
pooja par
Ranch Hand

Joined: Feb 14, 2011
Posts: 31
you are displaying the data in the div tag and not textfield.
In your code you have mentioned

Give an id to the textfield

Change in function

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: autocomplete using ajax