0

I'm working on a java web application, I m using spring mvc and jsp pages.

What I am doing: On a jsp page, I m receiving from a controller an arraylist with wave objects, which are defined as a java class (model) and contain the attributes: name, start date, end date.

I am populating a dropdown element from the arraylist with the attribute. name for the wave objects.

<c:forEach var="wave" items="${waveList}" varStatus="iter">         
<option value="${wave.name}">${wave.name}</option>
</c:forEach>    

The problem: How can I use the other attributes (startdate, enddate), for the wave which is selected from the dropdown and show them on the jsp page, under the dropdown, without refreshing the page.

I know I have to use javascript, but i don't know javascript, I'm guessing it's not a complicated thing to achieve this. If you guys could give me the answer or direct me to a tutorial or something... I would appreciate it!

Exa
  • 4,020
  • 7
  • 43
  • 60
Adrian Bob
  • 741
  • 2
  • 12
  • 32

2 Answers2

0

you need to use AJAX to query the server to get the extra information from the server.

I think w3c issued a great tutorial for AJAX, you don't need to know a lot about JS

http://www.w3schools.com/ajax/ajax_intro.asp

After you understood the basic principle of JS and AJAX, you need a framework to do good and easy JS. I advice jQuery: http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery

Baptiste Pernet
  • 3,318
  • 22
  • 47
0

If you could make slight design change you could avoid the additional HTTP (AJAX) request.

<option value="${wave.name}">${wave.name}</option>

Instead of "name" in value attribute, you could store your end date and start date as a string with a delimiter (enddate::startdate) and in JS you could define an onclick/onSelect/onChange listener for the select retrieve the selected value.

For Javascript snippet for Select (HTML): Get selected value in dropdown list using JavaScript?

Community
  • 1
  • 1
bmusical
  • 244
  • 3
  • 14