Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Ajax To display suggestions in a text box
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


naveen
To display suggestions in a text box
3 Answer(s)      6 years and 2 months ago
Posted in : Ajax



Advertisement
View Answers

October 13, 2008 at 3:55 PM


Hi friend,


This can be done by using the Ajax :

Some steps to be memeber :

1)Create a text box on the JSP Page.
2)On this text box call a function onKeyUp event using Ajax.
3)Pass the value of Keyword to process page Using Ajax.
4)After getting the response you display all the result corressponding
to the keyword.

For more information on Ajax visit to :

http://roseindia.net/ajax/

http://www.roseindia.net/jsp/comboSelect.shtml

http://www.roseindia.net/jsp/popup-window-using-ajax-in-jsp.shtml

Thanks




October 13, 2008 at 4:59 PM


follow the steps for getting full source code.

1) Go to flazx.com, Search for Ajax Book
2) Download Book "Ajax on Java"
3) Open the Book and find the below content.
chapter 5
===========
+ Section 5.2
--------------
++ Example 5.4
..................

Rajanikant


October 13, 2008 at 6:13 PM


The code which i am using for my requirement is:

(Here, i am using the static content, i.e, not using database code.)


Sample.html
------------

<html>
<head>
<title>Sample</title>
<head>
<script type="text/javascript" language="javascript">

var xmlHttp;
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txt1").innerHTML="";
return;
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="gethint.jsp";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txt1").value=xmlHttp.responseText;
}
}
</script>
</head>
<body>
<form>
First Name:<input type="text" id="txt1" name="put" onkeyup="showHint(this.value)">
</form>
</body>
</html>


gethint.jsp
------------

<html>
<head>
<title>
gethints</title>
<body>
<%
String a[]=
{
"Anna",
"Brittany",
"Cinderella",
"Diana",
"Eva",
"Fiona",
"Far",
"Gunda",
"Hege",
"Inga",
"Johanna",
"Kitty",
"Linda",
"Nina",
"Ophelia",
"Petunia",
"Amanda",
"Raquel",
"Cindy",
"Doris",
"Eve",
"Evita",
"Sunniva",
"Tove",
"Unni",
"Violet",
"Liza",
"Elizabeth",
"Ellen",
"Wenche",
"Vicky"
};
String q=request.getParameter("q");
String hint="";

if(q!=null)
{
for(int i=0;i<a.length;i++)
{
if(a[i].toUpperCase().startsWith(q.toUpperCase()))
{
hint=hint+""+a[i];
}
}
}
else{
hint="";
}
if(hint==null||hint.length()==0)
response.getWriter().write("no Suggestion");
else{
response.getWriter().write(hint);
}

%>
</body>
</html>



Output i am getting is:

First Name: f

Result is:

First Name: FionaFar<html><head><title>gethints</title><body></body></html>

The result which i am getting is wrong.

It has to display:
First Name: Fiona
Far

Then, i have to select only one.

Please correct me, if i did any mistake.

Thanks and Regards,
Naveen.



Related Tutorials/Questions & Answers:
To display suggestions in a text box - Ajax
To display suggestions in a text box  Hi All, I have a requirement, to get the suggestions i mean when i enter the alphabet in a text box(For ex:'A'), the names that starts from 'A' have to display in the text box
Automatically display in text box - JSP-Servlet
Automatically display in text box  Dear Deepak Sir, When i enter some text in text box.That corresponding value in database,the value display in another text box using ajax. Thanks & Regards, VijayaBabu.M
Advertisements
how to display webservice response in a text box
how to display webservice response in a text box  Hallo, i have created a webservice and when i sended request to my webservice its sending proper response . the point is how to dispaly the response values in a text box usinj
Display two alert box alternately by clicking on text
Display two alert box alternately by clicking on text In this tutorial , we will discuss about how to display two alert box alternately by clicking on text line. In this example, a text line is given ,when we click
display diffrence between two dates in a text box - JSP-Servlet
display diffrence between two dates in a text box  i have these set of codes // String di=request.getParameter("timestamp2"); String d2... the days in another text box when i click inside that test box.lease help me
how to display data from mysql table in text box using jsp??
how to display data from mysql table in text box using jsp??  <p>hi, i have a written a code to display data from a mysql table into txtboxes...="row">Reference GPC</th> 113: <td><input type="text" name
Display current date in text box in JSP using javascript
Display current date in text box in JSP using javascript In this section you will learn how to display current date in text box using JavaScript.For...; Today's Date is: <input type="text" id="datetext"> <
Simple Text display
to display any text in a text input box using a button click. It is very simple... Simple Text display     ... that flex panel we have to use a button and a textinput box which are present
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
Text box Checking
Text box Checking  I want to Write only the word A-Z in a text box What is the code
two text box problem
two text box problem  i have two text box in two different pages and same variable use in two text box when enter value in first text box it's reflection show in second text box , how i reduce it in jsf ?   Hi Friend
java script text box
will click submit button the text should be submitted(it shows the value in alert). i also want the text box should generate in front of NEW button(next/prev...java script text box  hi, I created a button when i click
enable text box
enable text box  Dear all I would like to enable a textbox by clicking on a button. pleas ehelp me out how can i do this regards JV
enable text box and label on selection
enable text box and label on selection  hello, Please tell me how to enable label and text box on selection of drop down list box. in drop down list box all values come from database. please reply
Text box control--keypress event
Text box control--keypress event  In my form have a text box...My requirement is... when is type characters in that box... before typing the 3rd character the space should come automatically or programmatically...the sturucture
Fancy Box plug-in for text, portal & swf file
Fancy Box plug-in for text, portal & swf file In this section, you will learn how to display text, portal & swf file inside fancy box by clicking... click on any link like text, portal & swf file, the output will be open
Drag a Text Box into dynamic positions
Drag a Text Box into dynamic positions  Plz can anyone tell how can i drag a text box using mouse or arrow keys... Im doing a accounts projects and i need this feature for cheque configuration
auto complete text box - Ajax
auto complete text box  How to create auto complete text box in jsp using ajax technology ? plz giv me steps wise code
J2ME Text Box Example
J2ME Text Box Example       This application illustrates how to create the text box using TextBox class. The TextBox class is a Screen that allows the user to enter and edit text
how to create a text box using awt
how to create a text box using awt  give an example how creat multi buttons & text boxes
Auto Complete Text Box - JSP-Servlet
Auto Complete Text Box  Please help me in Aotocomplete text box code. I m a java programmer. I m working on jsp tech. please give me the code for Autocomplete text box in which the values will generate from database table
create text box by clicking button and submittong text in text box using submit
create text box by clicking button and submittong text in text box using... is created. and i want to do that when i enter the text input in text box and when i... box in SOP). i also want the text box should generate in front of NEW button
How to assign a default value to text box in netbeans
How to assign a default value to text box in netbeans  I have a java application,and i want to assign a default variable to the textbox
Name Display in alert box - JSP-Servlet
Name Display in alert box  Dear Sir, Please any one help me......... when i enter some value in text that value is already in database display the alert box but the value is not in data base alert box is not display
JSP Text Box properties. - JSP-Servlet
JSP Text Box properties.  How do I restrict a text box created in JSP page only for numbers.. example: I have a function something like this in actionscript UserID_txt.restrict = "0-9abc^d-zA-Z~!@#$%^&*()+_-'.,"; Do i have
display from select box - JSP-Servlet
display from select box  I am doing a jsp project. In this jsp project i have to show the photos in one cell depending on the selection from other selection box which is in the same page. The photos are stored
Auto Complete Text Box - JSP-Servlet
Auto Complete Text Box - JSP-Servlet  Auto Complete Text Box Please help me in Aotocomplete text box code. I m a java programmer. I m working on jsp tech. please give me the code for Autocomplete text box in which the values
On click Checkbox values displayed in text box
On click Checkbox values displayed in text box  Hi sir, If i onclick the checkbox values should be displayed in text box, the following code is working properly in Internet Explorer browser but its not working in Google chrome
On click Checkbox values displayed in text box
On click Checkbox values displayed in text box  Hi sir, If i onclick the checkbox values should be displayed in text box, the following code is working properly in Internet Explorer browser but its not working in Google chrome
Change background color of text box - Java Beginners
Change background color of text box  Hi how can i change the background color to red of Javascript text box when ever user enters an incorrect value while on entering a correct value its background color should change green
populating text box using jsp code
populating text box using jsp code  Sir, How to populate related values in a text box after selecting value from drop down list using JSP and mysql...").selectedIndex; var val = document.getElementById("book").options[cid].text
Advertisements
 

 

 

DMCA.com