SgtGranite
Programmer
Hello there, people!
I'm new to Javascript, and I'm having a very strange problem.
What should happen is that if one of three text fields was blank, when the second image was clicked, an alert should appear, requiring the due data. If all the fields were filled, the code was supposed to submit the form. Now what happens is that whenever any of the images is clicked, they trigger their respective actions, but the form will ALWAYS be submitted. Even if the text fields are blank. Even if the image clicked was the second one, the one for the popup window. WTF is happening?
Please, take a look at my code:
Any help will be much appreciated.
Thanks in advance.
I'm new to Javascript, and I'm having a very strange problem.
What should happen is that if one of three text fields was blank, when the second image was clicked, an alert should appear, requiring the due data. If all the fields were filled, the code was supposed to submit the form. Now what happens is that whenever any of the images is clicked, they trigger their respective actions, but the form will ALWAYS be submitted. Even if the text fields are blank. Even if the image clicked was the second one, the one for the popup window. WTF is happening?
Please, take a look at my code:
Code:
<script>
function check(){
var go = true;
if(document.contact.name.value ==""){
alert("Inform your name");
document.contact.name.focus();
go = false;
}else if(document.contact.phone.value ==""){
alert("Inform your phone number");
document.contact.phone.focus();
go = false;
}else if(document.contact.pass.value ==""){
alert("Inform your password");
document.contact.pass.focus();
go = false;
}else if(go == true){
document.contact.submit();
}
</script>
<form name="contact" id="contact" method="post" action="admin/acao/client_cadastre.php?acao=inserir">
<input type="text" name="name" id="name">
<input type="text" name="phone" id="phone">
<input type="text" name="pass" id="pass">
<img type="image" src="images/imageA.jpg" onclick="Javascript: window.open("falecon.php","Falecon","location=1,status=1,scrollbars=1,width=350,height=350");mywindow.moveTo(600,400);" />
<img type="image" src="images/imageB.jpg" onclick="check()" />
</form>
Any help will be much appreciated.
Thanks in advance.