B
Bartosz Wegrzyn
I use onblue event to validate fields in my form.
I do this onblur="return isname()" and so so ...
I have one form with 20 fields.
My problem is that when the focus is for example on the first field of my
form
the "name" field and I click somewher or press tab than I loose focus and my
isname() function is executed. Everything is fine but the focus was change
for next field
lets say "address" and the next function is executed isaddress(). Although
my isname() function tries to change the focus back to name field the other
function is executed.
This cause infinite loop and I cannot access the form anymore.
I know I can use the onchange() event handler but for me it will not work.
I need onblur(). Is this code wrong. Maybe the way I code is bad. Please
help.
THE CODE:
function iscustomerid() {
var string1 = document.form1.customerid.value;
if (string1 == "") {
}
return true;
}
function isname() {
var string2 = document.form1.name.value;
if (string2 == "" ) {
alert("Value is required");
document.form1.name.focus();
document.form1.name.select();
return false;
}
else {
if (string2.split(" ").length < 2) {
alert("Enter a full name");
document.form1.name.focus();
document.form1.name.select();
return false;
}
}
return true;
}
function isaddress() {
var string3 = document.form1.address.value;
if (string3 == "" ) {
alert("Value is required");
document.form1.address.focus();
document.form1.address.select();
return false;
}
return true;
}
function iscity() {
var string4 = document.form1.city.value;
if (string4 == "") {
alert("Value is required");
document.form1.city.focus();
document.form1.city.select();
return false;
}
return true;
}
function isstate() {
var string5 = document.form1.state.value;
if (string5 == "") {
}
return true;
}
function iszipcode() {
var string6 = document.form1.zipcode.value;
if (string6 == "") {
alert("Value is required");
document.form1.zipcode.focus();
document.form1.zipcode.select();
return false;
}
return true;
}
function isemail() {
var string7 = document.form1.email.value;
if (string7 == "") {
}
return true;
}
function isphone() {
var string8 = document.form1.phone.value;
if (string8 == "") {
alert("Value is required");
document.form1.phone.focus();
document.form1.phone.select();
return false; }
return true;
}
function isss() {
var string9 = document.form1.ss.value;
if (string9 == "") {
}
return true;
}
function iscc() {
var string10 = document.form1.cc.value;
if (string10 == "") {
}
return true;
}
function isexp() {
var string11 = document.form1.exp.value;
if (string11 == "") {
}
return true;
}
function isdate() {
var string12 = document.form1.date.value;
if (string12 == "") {
alert("Value is required");
document.form1.date.focus();
document.form1.date.select();
return false;
}
return true;
}
function istime() {
var string13 = document.form1.time.value;
if (string13 == "") {
}
return true;
}
function isservice() {
var string14 = document.form1.service.value;
if (string14 == "") {
alert("Value is required");
document.form1.service.focus();
document.form1.service.select();
return false;
}
return true;
}
function isdue() {
var string15 = document.form1.due.value;
if (string15 == "") {
alert("Value is required");
document.form1.due.focus();
document.form1.due.select();
return false;
}
return true;
}
function isextrawork() {
var string16 = document.form1.extrawork.value;
if (string16 == "") {
}
return true;
}
function isdue2() {
var string17 = document.form1.due2.value;
if (string17.value == "") {
}
return true;
}
function isspecial() {
var string18 = document.form1.special.value;
if (string18 == "") {
}
return true;
}
function iscompany() {
var string19 = document.form1.company.value;
if (string19 == "") {
}
return true;
}
function isinstaller() {
var string20 = document.form1.installer.value;
if (string20 == "") {
}
return true;
}
function check() {
alert('Thank You. Now print the work order');
return true;
}Thats how my validate script looks like:
I do this onblur="return isname()" and so so ...
I have one form with 20 fields.
My problem is that when the focus is for example on the first field of my
form
the "name" field and I click somewher or press tab than I loose focus and my
isname() function is executed. Everything is fine but the focus was change
for next field
lets say "address" and the next function is executed isaddress(). Although
my isname() function tries to change the focus back to name field the other
function is executed.
This cause infinite loop and I cannot access the form anymore.
I know I can use the onchange() event handler but for me it will not work.
I need onblur(). Is this code wrong. Maybe the way I code is bad. Please
help.
THE CODE:
function iscustomerid() {
var string1 = document.form1.customerid.value;
if (string1 == "") {
}
return true;
}
function isname() {
var string2 = document.form1.name.value;
if (string2 == "" ) {
alert("Value is required");
document.form1.name.focus();
document.form1.name.select();
return false;
}
else {
if (string2.split(" ").length < 2) {
alert("Enter a full name");
document.form1.name.focus();
document.form1.name.select();
return false;
}
}
return true;
}
function isaddress() {
var string3 = document.form1.address.value;
if (string3 == "" ) {
alert("Value is required");
document.form1.address.focus();
document.form1.address.select();
return false;
}
return true;
}
function iscity() {
var string4 = document.form1.city.value;
if (string4 == "") {
alert("Value is required");
document.form1.city.focus();
document.form1.city.select();
return false;
}
return true;
}
function isstate() {
var string5 = document.form1.state.value;
if (string5 == "") {
}
return true;
}
function iszipcode() {
var string6 = document.form1.zipcode.value;
if (string6 == "") {
alert("Value is required");
document.form1.zipcode.focus();
document.form1.zipcode.select();
return false;
}
return true;
}
function isemail() {
var string7 = document.form1.email.value;
if (string7 == "") {
}
return true;
}
function isphone() {
var string8 = document.form1.phone.value;
if (string8 == "") {
alert("Value is required");
document.form1.phone.focus();
document.form1.phone.select();
return false; }
return true;
}
function isss() {
var string9 = document.form1.ss.value;
if (string9 == "") {
}
return true;
}
function iscc() {
var string10 = document.form1.cc.value;
if (string10 == "") {
}
return true;
}
function isexp() {
var string11 = document.form1.exp.value;
if (string11 == "") {
}
return true;
}
function isdate() {
var string12 = document.form1.date.value;
if (string12 == "") {
alert("Value is required");
document.form1.date.focus();
document.form1.date.select();
return false;
}
return true;
}
function istime() {
var string13 = document.form1.time.value;
if (string13 == "") {
}
return true;
}
function isservice() {
var string14 = document.form1.service.value;
if (string14 == "") {
alert("Value is required");
document.form1.service.focus();
document.form1.service.select();
return false;
}
return true;
}
function isdue() {
var string15 = document.form1.due.value;
if (string15 == "") {
alert("Value is required");
document.form1.due.focus();
document.form1.due.select();
return false;
}
return true;
}
function isextrawork() {
var string16 = document.form1.extrawork.value;
if (string16 == "") {
}
return true;
}
function isdue2() {
var string17 = document.form1.due2.value;
if (string17.value == "") {
}
return true;
}
function isspecial() {
var string18 = document.form1.special.value;
if (string18 == "") {
}
return true;
}
function iscompany() {
var string19 = document.form1.company.value;
if (string19 == "") {
}
return true;
}
function isinstaller() {
var string20 = document.form1.installer.value;
if (string20 == "") {
}
return true;
}
function check() {
alert('Thank You. Now print the work order');
return true;
}Thats how my validate script looks like: