Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with Drop Down menu population using Ajax and jQuery

 
Viswa Rama
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65223
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic