Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/04/2009, 10:33
Avatar de gilbeRt_fox
gilbeRt_fox
 
Fecha de Ingreso: octubre-2008
Ubicación: Asunción
Mensajes: 16
Antigüedad: 15 años, 6 meses
Puntos: 0
Pregunta Identificar el tipo de elemento

Hola amigos.. tengo el siguiente problema. Necesito identificar los elementos de un formulario por sus tipos.

Tendría un formulario básicamente de esta manera..

Código HTML:
<form name="formEjemplo" method="post" action="#">
  <select name="elSelect[1]" onchange="intercambiarParecido(this.id, this.value);">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
  </select><br />
  <select name="elSelect[2]" onchange="intercambiarParecido(this.id, this.value);">
    <option value="1">1<option>
    <option value="2">2<option>
    <option value="3">3<option>
  </select><br />
  <input type="submit" name="update" value="Actualizar" />
</form> 
Bueno.. mi funcion Javascript es la siguiente y ahi tengo el inconveniente..

Código HTML:
<script language="javascript">
     function intercambiarParecido(id, valor) {
          var cambiando = document.getElementById(id);
          var auxiliar = new HTMLOptionElement;
          for (var i=0; i < document.formEjemplo.elements.length; i++) {
               var elemento = document.formOrden.elements[i];
               if (elemento.type == "select" && elemento.id != cambiando.id){ 
                    if (elemento.value == valor) {
                         aux.value = cambiando.value;
                         cambiando.value = elemento.value;
                         elemento.value = aux.value;
                    }
               } 
          }
    }
</script> 
elemento.type == "select" ahi está el problema.

La funcionalidad sería tener varios selects y si en uno de estos select se selecciona un valor que ya otro select tiene entonces lo intercambia.. me explico!? es para guardar el orden de unos registros sin repetirlos.

Gracias desde ya!