• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

passing javascript parameter  RSS feed

Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a javascript function (ContentComboBox) that is called when a javascript OnChange event occurs.
the code on this javascript function is
"function ContentComboBox(distritos)
document.all.concelhos.innerHTML = <%=DataBase(xxx)%>;
DataBase is a java function and xxx is the value of the javascript variable distritos.
My problem is: How do i pass the value of distritos, which is a javascript variable, into the Java function (DataBase). What�s the sintax?
Thanks for the help.
Claudia Vaz
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have half of your answer...
Using the JSP expression tags wont do what you want. The value of the tag is evaluated before the content is sent to the browser. When the JSP is turned into a servlet the <%= .... %> is turned into an out.println statement in the service method.
What you want to do is have your javascript function call a Java method on the server, and that's the part I dont kow how to do, or if it can be done easily. You might want to check the HTML/Javascript forum.
hope that helps a little bit...
Author and ninkuma
Posts: 66820
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Dave pointed out, the approach you are taking isn't the way that Servlets and JSP work. All the Java in your JSP file is evaluated prior to sending the page out to the browser in order to create the HTML document that will be sent. The only way to "call back" to Java on the server is by submitting a new request.
That said, it looks like you are trying to populate the content of a select list from database info. What you should do in this case is to have a display helper routine that will grab the values from the database (or preferably from a database delegate if you are trying to keep your layers clean) and generate the required option tags to send the browser. In this way, the HTML representing the list content is set into the page before it is sent to the browser.
[ May 13, 2002: Message edited by: Bear Bibeault ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!