Question subject: Ajax Source code to Suggest application with JSP Server side
Posted: Tue Aug 07, 2007 12:18 pm
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2103 Location: Earth Has thanked: 39 time Have thanks: 57 time
Hi,, This is application i made .It is a well know application.The main idea that when the user hit a word in the text input .The Browser send this word to the server.The Server search for a words that start with the same as the input start and replay back with an HTML code include these words.The Browser then take this response words and view it to the users .An live example on this is the Google suggestion [color=#0000BF]Here[/color].In the server side i am using JSP.If you don't know JSP you can create your server page with the programming language you want for example (PHP,ASP,..etc).Also you can add more features to this small Ajax application .for example you can use the database to get the suggestion words like Google does. Here is the JavaScript code which called (Ajaxsc.js)
Code:
// Ajaxsc.js // doSuggest /* Writen by Mohamed Sami Developer Information Technology mail :msi_333@yahoo.com */ function doSuggest(word) { if(word.length>0) { var request=null; if (window.XMLHttpRequest) { request = new XMLHttpRequest(); } else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); }
if(request) { var url="Page1.jsp"; url+="?suggestword="+word;
<!-- Writen by Mohamed Sami Developer Information Technology mail :msi_333@yahoo.com --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Writen by Mohamed Sami Developer Information Technology mail :msi_333@yahoo.com --> <HTML> <HEAD> <script type="text/javascript" src="Ajaxsc.js"></script> <TITLE>index.html</TITLE>
<div id = "theResults" style = "width:22em;border:1px black solid;padding-left:2px;padding-right:2px; visibility: hidden"> </div>
</BODY> </HTML>
Thats was all the files in the project .You can run it in your local host.But remember that you must have a JSP container to run the JSP file like (Tomcat , JBoss,..etc). If you faced any bugs while trying please reply my topic with the error ,
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
dipesh3535
Question subject: Re: Ajax Source code to Suggest application with JSP Server side
Posted: Thu Aug 05, 2010 12:15 pm
Joined: Thu Aug 05, 2010 12:00 pm Posts: 1 Has thanked: 0 time Have thanks: 0 time
thanks
msi_333
Question subject: Re: Ajax Source code to Suggest application with JSP Server side
Posted: Sat Aug 07, 2010 12:35 am
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2103 Location: Earth Has thanked: 39 time Have thanks: 57 time
you are welcome .
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
fei7shi91
Question subject: Re: Ajax Source code to Suggest application with JSP Server side
Posted: Thu Aug 19, 2010 7:48 am
Joined: Thu Aug 19, 2010 7:32 am Posts: 1 Has thanked: 0 time Have thanks: 0 time
thanks for you sharing
_________________ http://www.ghd-hair.co.nz
tanaytandon
Question subject: Re: Ajax Source code to Suggest application with JSP Server side
Posted: Wed Dec 29, 2010 9:52 am
Joined: Wed Dec 29, 2010 9:45 am Posts: 1 Has thanked: 0 time Have thanks: 0 time
Thanks for sharing the solution. I have a question is there a way we can tweek your code so that if we select one of the items from the suggested list it populates into the text box. Something like what happens in Google.
Thanks In Advance, Tanay Tandon
Yoshimitzu
Question subject: Re: Ajax Source code to Suggest application with JSP Server side
Posted: Tue Jan 17, 2012 3:58 pm
Yes, you can. you have modify only one row in Page1.jsp, in this mode: