This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JSP and the fly likes Help with value change of select tag on jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Help with value change of select tag on jsp page" Watch "Help with value change of select tag on jsp page" New topic
Author

Help with value change of select tag on jsp page

Arpit Maheshwari
Greenhorn

Joined: Dec 06, 2011
Posts: 5
What I want to do:
I have a jsp page where initially there is a single html select tag with its options retrieved from database that contains the list of moderators assigned.
On value change of the the select box i want to show the detailed description of the moderator on the same page.

Problem:
The problem is I cant get the way to retrieve data on value change as I cant take the value change from javascript and pass this value as parameter in java to retrieve the description.

So how to detect the value change in jsp...
Or suggest me some other way to deal with this problem...
J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 380
    
    3

I don't see any other solution except an AJAX call. Use the JQuery onchange() event to get the option value and use that as a parameter to the AJAX call to get the description. Then insert the description into the DOM using JQuery.


"I have a mind like a steel... uh... thingy."
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 503

Well, the solution of AJAX suggested by Robbins is absolutely fine. I just wanted add a few points, onchange() is not an JQuery event, its an HTML event and the problem OP is having, can be solved without using JQuery also, but yes, JQuery would make it much easier, but it should be left at the discretion of OP to whether use JQuery or any other framework.


Regards, Prasad
SCJP 5 (93%)
J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 380
    
    3

Yes, you are correct about leaving that choice to the posters discretion. My experience is with JQuery, so I'm biased that way.

JQuery, ExtJS, MooTools... whatever your favorite Javascript framework happens to be, they all make life easier than raw Javascript.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56183
    
  13

I agree with Jk... life is too short to write raw JavaScript without jQuery. Especially if Ajax is going to come into the picture!


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Arpit Maheshwari
Greenhorn

Joined: Dec 06, 2011
Posts: 5

So I have to make an AJAX call for it....
Thank you everyone for the help....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56183
    
  13

You don't have to... you can go old-school and simply refresh the entire page, using JSP to add the new elements. But that would be so 2001...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with value change of select tag on jsp page
 
Similar Threads
Struts and JSP problem
How to refer a java variable in javascript code.
Using html:select
populate items using struts2 <s:select>
SCWCD mock questions II