Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/10/2013, 06:12
Avatar de CMushroom
CMushroom
 
Fecha de Ingreso: diciembre-2011
Ubicación: Morelos
Mensajes: 99
Antigüedad: 12 años, 3 meses
Puntos: 1
Pregunta getElementById

Alguien me puede decir por que no valida mas que el input. Nesesito validarlos por getElementById.

Código:
<script type="text/javascript">
    function validar() 
		{
        miCampoTexto = document.getElementById("input").value;

        if (miCampoTexto.length == 0) 
			{
			alert("input vacio")
            return false;
        	}
		else
			{
			alert("input lleno")
        	return true;
			}
		
		indice = document.getElementById("select").selectedIndex;
		if(indice == null || indice == 0) 
			{
			alert ("Select no seleccionado")
			return false
			}
		else
			{
			alert ("Select seleccionado")
			return true
			}

		var a = 0, radioboton = document.getElementsId("radio")
		for(i = 0; i < radioboton.length; i++) 
			{
			if(radioboton.item(i).checked == false) 
				{
				a++;
				}
			}
		if(a == radioboton.length) 
			{
			alert("Radio no seleccionado");
			return false;
			} 
		else 
			{
			alert("Radio seleccionado");
			return true;
			}

		var b = 0, botoncheckbox = document.getElementsById("checkbox")
		for(i = 0; i <botoncheckbox.length; i++) 
			{
			if(botoncheckbox.item(i).checked == false) 
				{
				b++;
				}
			}
		if(b == botoncheckbox.length) 
			{
			alert("Checkbox no seleccionado");
			return false;
			} 
		else 
			{
			alert("Checkbox seleccionado");
			}
    }
</script>
Código HTML:
<form name = "formulariocomponentes" action = "" onsubmit = "return validar()">
    <input type = "text" id = "input" name = "input">
    <br>
    <select id = "select" name = "opciones">
        <option value>Seleccione una opcion</option>
		<option value = "1">Primer valor</option>
		<option value = "2">Segundo valor</option>
		<option value = "3">Tercer valor</option>
        <option value = "4">Cuarto valor</option>
    </select>
    <br>
    <input type = "radio" id = "radio" value = "1">Mexico<br>
    <input type = "radio" id = "radio" value = "2">Brazil<br>
    <input type = "radio" id = "radio" value = "3">España<br>
    <input type = "radio" id = "radio" value = "4">Francia<<br>
    <br>
    <input type = "checkbox" id = "checkbox" value = "1">Primer valor<br>
    <input type = "checkbox" id = "checkbox" value = "2">Segundo valor<br>
    <input type = "checkbox" id = "checkbox" value = "3">Tercer valor<br>
    <br>
    <input type = "submit" value = "Enviar">
</form>