• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

autocomplete using ajax

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic