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

  1. Genial ese plugin para jQuery!

    Hace 6 o 7 años tuve que implementar algo muy parecido, y no existía este plugin ni jQuery, así que tuve que hacer todo con código 100% javascript, sin ayuda de frameworks javascript ni nada… realmente fue un cacho! :P

    Saludos!

Leave a Comment

*


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

Rss Feed Tweeter button Facebook button Technorati button Reddit button Linkedin button Webonews button Delicious button Digg button Flickr button Stumbleupon button Newsvine button Youtube button