Kyryus Posted May 6, 2008 Report Share Posted May 6, 2008 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 Report Share Posted May 6, 2008 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 Author Report Share Posted May 13, 2008 nao da à mesma 😄 Link to comment Share on other sites More sharing options...
Battousai Posted May 13, 2008 Report Share Posted May 13, 2008 <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 Report Share Posted May 13, 2008 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 Report Share Posted May 13, 2008 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