Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/08/2005, 11:14
Avatar de monoswim
monoswim
$moderador{'Esteban'}
 
Fecha de Ingreso: febrero-2002
Ubicación: Buenos Aires - Argentina
Mensajes: 8.762
Antigüedad: 22 años, 7 meses
Puntos: 90
Ordenar un Select alfabéticamente por el text: Solución

Hola, hace unos días realicé un post sobre como ordenar alfabéticamente un select y luego de algunas ayudas y pelear un poco lo logré !!!

Acá va el código para el que lo necesite !!!

Código:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
function ordena2()	{
	var regs = [];
	with (document.forms["formulario"]["registros"])	{
		for (var i = 0; i < options.length; i ++){
		   regs[i] = options[i].text + '|||' + options[i].value;
		}	
		options.length = 0;
		regs.sort();
		for (var i = 0; i < regs.length; i ++){
			var cols = [];
			cols = regs[i].split('|||');
			options[i] = new Option(cols[0],cols[1]);
		}		   
	}
}
</script>
</head>

<body>
<form action="" method="post" name="formulario" id="formulario">
  <p> 
    <select name="registros">
      <option value="1">Quintana</option>
      <option value="2">Hernandez</option>
    </select>
    <input type="button" name="Button2" value="Button" onClick="ordena2()">
  </p>
  </form>
</body>
</html>
Espero que les sirva
Saludos
__________________
Esteban Quintana