Category Archives: jQuery

Enviar datos entre dos select usando jQuery

Hoy me vi en la necesidad de implementar dos select los cuales se enviaban información entre ellos (los típicos usados para seleccionar ciertos elementos de un conjunto). Encontre un plugin de jQuery muy útil (básicamente hace todo por nosotros).

Se llama Dual Listbox, su utilización es la siguiente.


$.configureBoxes({
box1View:'PollIds',
box2View:'PollId',
);

con box1View establecemos cual será el select 1 y con box2View el select 2, existen muchas opciones todas documentadas en su página web.

Finalmente para enviar la información se debe usar un pequeño truco (gracias Bilson), el cual consiste en seleccionar todos elementos del select 2 utilizando javascript al enviar el formulario.




function selectAll(selectBox,selectAll) {
// have we been passed an ID
if (typeof selectBox == "string") {
selectBox = document.getElementById(selectBox);
}
// is the select box a multiple select box?
if (selectBox.type == "select-multiple") {
for (var i = 0; i < selectBox.options.length; i++) {
selectBox.options[i].selected = selectAll;
}
}
}

La función de Javascript fue extraída desde qodo.co.uk