It's not a secret anymore!
The moose likes Servlets and the fly likes calling jsp function inside html event Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "calling jsp function inside html event" Watch "calling jsp function inside html event" New topic

calling jsp function inside html event

kamlesh jainani

Joined: May 09, 2001
Posts: 5
i have a code that looks something like this:
<select name = company
onchange = "showbranchonoption(this.selectedindex); return false;">
the showbranchonoption function is a JSP function. it doesn't work this way. i appreciate any help.. pls..
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

It looks like you're getting confused with server side and client side code.
All JSP code is executed on the server and the result is a HTML page that gets sent to the client. That HTML can contain JavaScript code that gets sent inside the page.
The 'onChange' function is JavaScript which is executed on the clients browser. As such, it has no mechanism to access the JSP code or to change the way the JSP behaves. It is on the client and the JSP code is on the server.
It's allowable to call a JavaScript function embedded in the HTML page though.
Hope this helps,
kamlesh jainani

Joined: May 09, 2001
Posts: 5
my database is in the server, my problem is this: i have two option boxes or a combo boxes that displays the contents of the company table and its branch. each time a user selects a company the branch option box refreshes and displays the corresponding branches of the company selected. my idea was to use a java class for this or a jsp but since you said the event onchange is a javascript hook what is the best way for me to call my function and pass the parameters of my html code
by the way thanks for replying!!
-- kamlesh
Pallavi G

Joined: May 07, 2001
Posts: 5
Hi there,
I went trhough your reply. In that case if you need to change the contents of one option box, depending on the selection of others (without going to server and refreshing the page again). yo can do it through DHTML, provided you dont have too many records in Database.
Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
OR, if you are keen to experiment, you can do remote scripting using a servlet.. here's an overview
I have used this in the past and is a very cool way to do what you want..
[This message has been edited by Mak Bhandari (edited May 11, 2001).]
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
"Pallavi G",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
kamlesh jainani

Joined: May 09, 2001
Posts: 5
hey guys thanks for all ur replies. i'll try mak's suggestion and find my way through it. thanks for all the patience guys...
i'll try to help you guys if i can to return the favor... thanks again...
I agree. Here's the link:
subject: calling jsp function inside html event
It's not a secret anymore!