Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

passing javascript parameter  RSS feed

 
Claudia Vaz
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
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
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Claudia
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...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
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.
hth,
bear
[ May 13, 2002: Message edited by: Bear Bibeault ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!