Kyryus Posted May 6, 2008 at 10:25 AM Report Share #183562 Posted May 6, 2008 at 10:25 AM tenho o seguinte codigo... [pre]<html> <head><title>Formularios</title> <script> function Validar() { if(form1.nome.value=="") window.alert("Perigo!!!"); } </script> </head> <body> <form name="form1"> <fieldset> <legend align="center">Dados Pessoais</legend> Nome: <input type="text" name="nome"> <br> Morada: <input type="text" name="morada"> <br> CP: <input type="text" name="cp" size=4> - <input type="textbox" name="cp2" size=6> Localidade: <input type="text" name="local"> </fieldset> <fieldset> <legend align="center">Disciplinas</legend> Tecnológicas<br> <input type="checkbox" name="api">API <input type="checkbox" name="bp">BP <input type="checkbox" name="ti">TI <input type="checkbox" name="ati">ATI <input type="checkbox" name="tgbd">TGBD <br> Curso <select name="cursos"> <option>Informática</option> <option>Desporto</option> <option>Humanidades</option> <option>Administração</option> </select> </fieldset> <input type="submit" name="sub" value="Submeter" onClick = validar()> <input type="reset" name="reset" value="Limpar"> </form> </body> </html>[/pre] o window.alert nao funciona! ja tentei de varias maneiras e nao da... alguem sabe porque? Link to comment Share on other sites More sharing options...
Battousai Posted May 6, 2008 at 11:21 AM Report Share #183564 Posted May 6, 2008 at 11:21 AM o nome da função está com letra grande e estás a chamar mal a função: onclick="validar()" Link to comment Share on other sites More sharing options...
Kyryus Posted May 13, 2008 at 09:55 AM Author Report Share #184792 Posted May 13, 2008 at 09:55 AM nao da à mesma 😄 Link to comment Share on other sites More sharing options...
Battousai Posted May 13, 2008 at 10:05 AM Report Share #184793 Posted May 13, 2008 at 10:05 AM <html> <head><title>Formularios</title> <script> function validar() { if(form1.nome.value==""){ alert("Perigo!!!"); return false; } } </script> </head> <body> <form name="form1" action="./pagina.php" method="post" onsubmit="return validar()"> <fieldset> <legend align="center">Dados Pessoais</legend> Nome: <input type="text" name="nome"> <br> Morada: <input type="text" name="morada"> <br> CP: <input type="text" name="cp" size=4> - <input type="textbox" name="cp2" size=6> Localidade: <input type="text" name="local"> </fieldset> <fieldset> <legend align="center">Disciplinas</legend> Tecnológicas<br> <input type="checkbox" name="api">API <input type="checkbox" name="bp">BP <input type="checkbox" name="ti">TI <input type="checkbox" name="ati">ATI <input type="checkbox" name="tgbd">TGBD <br> Curso <select name="cursos"> <option>Informática</option> <option>Desporto</option> <option>Humanidades</option> <option>Administração</option> </select> </fieldset> <input type="submit" name="sub" value="Submeter"> <input type="reset" name="reset" value="Limpar"> </form> </body> </html> Link to comment Share on other sites More sharing options...
asworm Posted May 13, 2008 at 10:07 AM Report Share #184794 Posted May 13, 2008 at 10:07 AM nao é por nada mas acho que deverias utilizar a escrita GeSHI ... facilita melhor a compreencao do codigo... como fez o Battousai cumps Got it? Link to comment Share on other sites More sharing options...
DanielAmorim Posted May 13, 2008 at 11:04 AM Report Share #184800 Posted May 13, 2008 at 11:04 AM Olá Tens ai uns quantos erros nessa página HTML... por exemplo: - Não fechas as tags de input e br - Na tag de script não indicas atributo o type. V como fazer aqui: http://www.w3schools.com/tags/tag_script.asp - Não preenches os atributos da tag form. Vê como fazer aqui: http://www.w3schools.com/TAGS/tag_form.asp - Os valores dos atributos não estão entre aspas (<atributo> : " <valor> ") Aconselho-te a instalares a extensão HTML Validator para o Firefox, irá ajudar-te bastante a detectar este tipo de erros. Depois de corrigir estas coisas fui ver porque não chamava a função e a explicação é simples. O Javascript é case-sensitive e tu definiste uma função com o nome Validar e estas a chamar uma função com o nome validar 😄 Daniel Amorim VP for xRTML http://www.xrtml.org http://www.realtime.co Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now