Ver Mensaje Individual
  #7 (permalink)  
Antiguo 12/04/2012, 17:34
Avatar de marlanga
marlanga
 
Fecha de Ingreso: enero-2011
Ubicación: Murcia
Mensajes: 1.024
Antigüedad: 13 años, 3 meses
Puntos: 206
Respuesta: select multiple seleccionar opciones

No uses el value.
Tienes que añadirle un atributo selected="selected" a cada <option> a seleccionar.


Array.prototype.contiene= function(obj) {
var i = this.length;
while (i--) {
if (this[i] === obj) {
return true;
}
}
return false;
}

function seleccionar(args)
{
var nodos=document.getElementById("pp").childNodes;
var n=nodos.length;
for (var i=0;i<n;i++)
{
if(nodos[i].nodeType == document.ELEMENT_NODE && args.contiene(nodos[i].value))
{
var att=document.createAttribute("selected");
att.nodeValue = "selected";
nodos[i].setAttributeNode(att);
}
}
}
seleccionar(["y","w"]);

http://jsfiddle.net/GbRxv/

Última edición por marlanga; 12/04/2012 a las 17:51