14
I have a select with 4 options. These 4 options are the number of options that will appear in a multiple select.
What I want is as soon as the user selects the option of number of frequently asked words, the javascript already fills the second select
with the number of words selected in the first select
.
For this, the largest option that the user can put is 20 and the code behind (in java) has a list of the 20 most frequent words. That is, I need a javascript function that takes the selected value in the first select
(X) and load the second select
with the first X elements of the list (in java).
So he can show up at select
the code is like this with the vector:
<select name="vet[]" size="4" multiple><%
for(int i=0;i<5;i++){ %> <option> <% out.print(documento.vetor[i]); %> </option><% } %>
</select> <br>
In this case, the for is with size 5 by default, but it is this number that I wish to change..
Where do the information that will fill in select? Ajax come from? Fixed in Javascript?
– André Ribeiro
@Andréribeiro is in a vector of size 20 (ordered).. I created the vector inside an object, which I used in java.
– Pacíficão
Add vector to your question to make it easier to view.
– André Ribeiro
@Andréribeiro ready. Look if helped understand
– Pacíficão
I would do this by exposing a REST service, e.g.,
/palavras?limite=5
. This service would return the list on the Java side. On the client side you can use the eventonchange
of the firstselect
to make an AJAX request for this new service by passing the newlimite
. Thecallback
AJAX request would simply clean theoptions
previous and would load newoptions
to the secondselect
as the words returned by the service.– Anthony Accioly