...

View Full Version : Form Validation Error!



alien
05-09-2006, 04:35 AM
I keep getting a syntax error for this. It says the error is on line 8, char 9, but I can't find anything wrong...Does anyone know how to fix it?



function confirmSubmit() {
if (document.forms[0].name_home.value == ""
|| document.forms[0].address_home.value == ""
|| document.forms[0].city_home.value == ""
|| document.forms[0].state_home.value == ""
|| document.forms[0].zip_home.value == "") {
window.alert("You must enter your home information");
return.false;
}
else if (document.forms[0].name_billing.value == ""
|| document.forms[0].address_home.value == ""
|| document.forms[0].city_home.value == ""
|| document.forms[0].state_home.value == ""
|| document.forms[0].zip_home.value == "") {
window.alert("You must enter your home information");
return.false;
}

else if (document.forms[0].area.value == ""
|| document.forms [0].exchange.value == ""
|| document.forms [0].phone.value == "") {
window.alert("You must enter a phone number");
return.false;

}

else if (document.forms[0].password.value == ""
|| document.forms[0].password_confirm.value == "") {
window.alert("You must enter a password");
return.false;
}
}

function confirmReset() {
var resetForm = confirm("Are you sure you want to reset the form?");
if (resetForm == true)
return true;
return false;
}

livescript
05-09-2006, 04:52 AM
Ah fortunately this is an easy fix.

all you have to do is arrange your if statement like this...


if(someElement.value == "" && someElement.value == null
|| someElement2.value == "" && someElement2.value == null)
{
execute this code.....
}

you have use use not only == "" but also == null. That should take care of your problem.

LiveScript

alien
05-09-2006, 03:27 PM
still getting the same error, line 8, char 10 now.

:confused:







function confirmSubmit() {
if(document.forms[0].name_home.value == "" && document.forms[0].name_home.value == null
|| document.forms[0].address_home.value == "" && document.forms[0].address_home.value == null
|| document.forms[0].city_home.value == "" && document.forms[0].city_home.value == null
|| document.forms[0].state_home.value == "" && document.forms[0].state_home.value == null
|| document.forms[0].zip_home.value == "" && document.forms[0].zip_home.value == null) {
window.alert("You must enter your home information");
return.false;
}

else if(document.forms[0].name_billing.value == "" && document.forms[0].name_billing.value == null
|| document.forms[0].address_billing.value == "" && document.forms[0].address_billing.value == null
|| document.forms[0].city_billing.value == "" && document.forms[0].city_billing.value == null
|| document.forms[0].state_billing.value == "" && document.forms[0].state_billing.value == null
|| document.forms[0].zip_billing.value == "" && document.forms[0].zip_billing.value == null) {
window.alert("You must enter your billing information");
return.false;
}

else if (document.forms[0].area.value == "" && document.forms[0].zip_billing.value == null
|| document.forms [0].exchange.value == "" && document.forms[0].exchange.value == null
|| document.forms [0].phone.value == "" && document.forms[0].phone.value == null) {
window.alert("You must enter a phone number");
return.false;

}

else if (document.forms[0].password.value == "" && document.forms[0].password.value == null
|| document.forms[0].password_confirm.value == ""&& document.forms[0].password_confirm.value == null) {
window.alert("You must enter a password");
return.false;
}
}

function confirmReset() {
var resetForm = confirm("Are you sure you want to reset the form?");
if (resetForm == true)
return true;
return false;
}

Kor
05-09-2006, 03:41 PM
You have writtem return false with a dot in the middle
replace
return.false
with
return false

livescript, your ideea seems not a good one. Do you think a value could be an empty string AND a null the SAME time?

It looks like the reset function is wrong. I guess the whole function has no sense. If the user presses the Reset button, that means he wants to reset the form, why asking for confirm?

(I hate most of the stupid Windows alerts "Are u sure you want to...". Damn I am sure, Mr. Gates, do you think I am dumb? ) :D

Anyway, if you want that by all means:


function confirmReset() {
var resetForm = confirm("Are you sure you want to reset the form?");
return resetForm;
}

alien
05-09-2006, 06:02 PM
Thanks, it works now :D :thumbsup:

livescript
05-11-2006, 06:19 PM
As far as the null goes it not setting an object such as a textbox to "null" such as a sting its setting it to null as in no value. With some opensource and linux browsers such as FireFox or Konquerer. The function will not work unless you have null too. Thats why I mentioned that, since I didnt know what browser he was using. I do feel stupid however since I didnt notice the return.false instead of return false.

Kor
05-12-2006, 08:04 AM
As far as the null goes it not setting an object such as a textbox to "null" such as a sting its setting it to null as in no value. With some opensource and linux browsers such as FireFox or Konquerer. The function will not work unless you have null too. Thats why I mentioned that, since I didnt know what browser he was using. I do feel stupid however since I didnt notice the return.false instead of return false.

Maybe. It is not the null value I was against. It was the AND operator (&&). I guess that should have been OR (||)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum