• 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

Call JSP function from onchange event

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I designed a form that have two drop down lists in a JSP file.
The options in the second list depends on the selected option of the first list and these results come from an XML file. Ok, this is not unusual.
I know how to do this using Javascript, but I want this to be different. I want to write a JSP function that return these results (that means, using DOM or SAX to manipulate the XML file and to populate the drop down with new options).
Here comes my 2 questions:
1 - How can I simulate the onchange event in this situation? That is, how can I call the JSP function when the user change the option selected in the first drop down list?
2 - After calling the JSP function, how can I print the results exactly in the second drop down list?
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since JSP is performed at compile time and not at run time, I don't think this is possible.
I suggest you use Javascript as you said you have done in the past.
 
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
Jeff is quite correct, you can't just call out to Java (the term 'JSP function' isn't very meaningful) from JavaScript on the page.
In order to go back to the server, you must submit a form or hit a URL in order to initiate the traditional request/response cycle.
So you have three primary choices:
1) Load up all the possibilities in JavaScript objects when the page is rendered so that you can use DHTML to manipulate the drop-downs.
2) Submit the page so that it is refreshed with the approriate values in the drop-downs.
3) Get really tricky and submit the request to an off-screen frame (usually an iframe of zero size), so that the current page does not refresh. However, JavaScript returned in the invisible frame can manipulate the dropdowns on the displayed page as approriate. Sort of the best of both worlds, but of course, trickier to implement and maintain.
hth,
bear
 
Hang a left on main. Then read 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