ParameterList without selection
I have a listbox set to multiple. I can select the lines for deletion from this listbox (via JavaScript). On Servlet side I need all entries of the listbox but I can't get the values from this listbox if the lines are not selected.
This is the way I have done to get the entries:
String[] listvalue = request.getParameterValues("listbox");
Thats correct behaviour. The browser will only send the entries in the list box that have been selected. If you always want to get them all then u need to mark them all as selected before you submit the form.You can do this using javascript.
function selectAll()
{
var sel = document.getElementById("yourSelectObjectID");
var opts = sel.options;
for (var i=0; i<opts.length; i++ )
{
opts[i].selected = true;
}
}
or if you want to invert the selections so that those not selected are sent to the server you can do :-
function invert()
{
var sel = document.getElementById("yourSelectObjectID");
var opts = sel.options;
for (var i=0; i><opts.length; i++ )
{
if ( !opts[i].selected)
opts[i].selected = true;
else
{
opts[i].selected = false;
}
}
}
or perhaps you want to send all regardless of whether they are selected or not but also want to know which they selected, so you would need to append something to the selected entries values :-
function mark()
{
var sel = document.getElementById("yourSelectObjectID");
var opts = sel.options;
for (var i=0; i><opts.length; i++ )
{
if ( !opts[i].selected)
opts[i].selected = true;
else
{
opts[i].value = opts[i].value + "_selected";
}
}
}
>