File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Issue with Drop Down menu population using Ajax and jQuery Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Issue with Drop Down menu population using Ajax and jQuery" Watch "Issue with Drop Down menu population using Ajax and jQuery" New topic
Author

Issue with Drop Down menu population using Ajax and jQuery

Viswa Rama
Greenhorn

Joined: Mar 19, 2012
Posts: 4
Hi Experts,

Scenario:

1. when i click a drop down box from JSP form select -> it calls a java script method -> which in turn makes ajax post request to servlet using jquery.
2. I receive the strings from servlets and append the options into the select.

Issue:
1. When i first click on the dropdown select, its showing none. - what is happening is its making the ajax call, however because the drop down is getting closed immediately, I am not able to see the data until i click this second time.
2. Secondly, because I used onclick event to run this script, every time i click the drop down, it keeps appending the options cumilatively.

Code:

HTML:


SCRIPT:


Your prompt will greatly be appreciated.

Thanks
Viswa.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56168
    
  13

Why are you waiting to get the options until the select element is clicked upon? Would it not be better to do that when the page initially loads? Or, as this a JSP, why aren't you just including them using JSP on the server rather than waiting until the page is displayed at the client and then using Ajax?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Issue with Drop Down menu population using Ajax and jQuery
 
Similar Threads
Dynamic drop down box
how to disable text area
Dynamic drop down list from an array
when i retrive data from access it showing empty page in tomcat
jQuery.ajax() issue with chrome and IE 8