Jump to content

Recommended Posts

Posted

Boa noite...

Estou a construir um formulario que tem de recolher o sexo do utilizador, eu construi o seguinte codigo que recolhe mas caso não selecione nada eu queria que desse um alert e não esta a funcionar....

<head>
function validateForm()
	{
if ( ( form.gender[0].checked == false ) && ( form.gender[1].checked == false ) ) 
				{ alert ( "Please choose your Gender: Male or Female" ); return false; }
				else
				{
					window.location="mail.php";
				}
}
</head>
<body>
                 Sexo : <input type="radio" name="gender" value="Male"> Male
	<input type="radio" name="gender" value="Female"> Female 
</body>

Linguagens: C / Java / Prolog / Assembly / HTMLA aprender: Java

Posted

Boas, vê se está bom assim, aqui está a funcionar 🙂

if ( document.forms["formulario"]["gender"][0].checked || document.forms["formulario"]["gender"][1].checked){ 
    var a=document.forms["formulario"]["ano"].value;
    if (a==null || a==""){
        alert("Por favor prencha os campos pedidos!");
return false;
    }else{
        window.location="mail.php";
    }
}else{
    alert ( "Please choose your Gender: Male or Female" );
    return false;
}

- Rui Fernandes

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.