i’ve an input type image like this:
<input type="image" name="formimage2" width="170" height="37" src="images/tasto-registrati.png" onclick="sub()">
this is sub():
function sub(){
var mail = document.getElementsByName('mail')[0];
var name = document.getElementsByName('name')[0];
if(mail.value!=""){
bool = true;
}else{
mail.value="Campo obbligatorio";
mail.style.backgroundColor="red";
bool=false;
}
if(name.value!=""){
bool = true;
}else{
name.value="Campo obbligatorio";
name.style.backgroundColor="red";
bool=false;
}
if(bool){
document.form[0].submit();
}
but form submit everytime! how can i tell to form to submit only in that case?
i try:
if(bool){
...
}else{
return false
}
but nothing! can you help me??
Just use
onclick="return sub()"I believe your form will not get submitted when it is
FALSE…Good Luck!!!
Update 1:
always use
return falseorreturn truein main function itself…javascript part
html part