mardi 21 mai 2019

How to randomly preselect item in Select in HTML

I think I need your help !

I explain myself.

I have a servlet in which I get a list of String. I pass the list in request.setAttribute("listProfenString",listProfenString);

Then, in my JSP, I get the list. Finally, I do a HTML form, in wich I add select> of the list I added in Attributes. Until there, no problem, I have my select> of my list of String.

What I want to do is to randomly pre select one item in this select> (I have multiple select>, but once I found for one, it's gonna be easier for the others!

Any advice, ideas to do that ? Preselect RANDOMLY (it's very important the random!) one item in my select> ?

List listProfenString = (List) request.getAttribute("listProfenString");

                                    <select name=prof id=binome11> 
                                    <% 
                                        for(int j=0;j<listProfenString.size(); j++) {
                                            out.println("<option>"+listProfenString.get(j)+"</option>");
                                        }
                                    %>
                                    </select>

                                    <select name=prof id=binome12> 
                                    <% 
                                        for(int j=0;j<listProfenString.size(); j++) {
                                            out.println("<option>"+listProfenString.get(j)+"</option>");
                                        }
                                    %>
                                    </select>

'''

Thank youu !




Aucun commentaire:

Enregistrer un commentaire