• 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

three dynamic lists to be populated from a servlet with ajax

 
Author
Posts: 47
5
MySQL Database PHP Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my problem is with the selected index property of a dynamic list that is populated from a servlet.

Let's say a list A is populated from a servlet. The inner HTML comes from the servlet as responseText and is used in the callBack function of ajax:

Here's the script:
s = xmlHttpRequest.responseText;
var drop = '<select name="' + dynaDiv + '" id="' + dynaDiv + '">' + s + '</select>';
document.getElementById(dynaDiv).innerHTML = drop;


where s comes from the servlet as:



Now if I want to create another list dynamically, let's say B, based on the selection in A, how do I retrieve the selected index of A in a script? I tried but it gives null. The aim is to generate a link of such lists. Moreover, I thought that since the list has been populated as a string(responseText rather than responseXML) the problem lies here. But if I change it to responseXML, how do return values from the servlet? (Given that I need one set for value and one for text)

Please help. It's a little Urgent.


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A change handler will tell you when a select element has been changed. You can grab the newly selected value and use it to fetch the next set of options for the subsequent select.

By the way, all of this is much (much much) easier with a library such as jQuery or Dojo.
 
Kanika Sud
Author
Posts: 47
5
MySQL Database PHP Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I used the following and it worked for me:

 
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic