An error is an error whether you created it or it just occurred. As such it will show up in any browser's error monitoring utility. IE is just (by default, it can be set by the user not to be) more obvious about this than others, but they all have ways and can be set to be as or more obvious about it than IE is.
It's really not all that much more code to do it correctly, even with strict indents and bracing:
Code:
function validate(){
if(isempty('name','Please enter your name')){
return;
}
}
function isempty(src,msg){
var so = document.getElementById(src);
if(so.value==''){
alert(msg);
so.focus();
return true;
}
return false;
}
If you are validating a bunch of fields:
Code:
function validate(){
var fields = [['name', 'name'], ['phonenumber', 'phone number'], ['address', 'address']];
for(var i = 0; i < fileds.length; ++i){
if(isempty(fields[i][0], 'Please enter your ' + fields[i][1])){
return;
}
}
}
function isempty(src,msg){
var so = document.getElementById(src);
if(so.value==''){
alert(msg);
so.focus();
return true;
}
return false;
}
Bookmarks