Ask a Question related to Macromedia Dynamic HTML, Design and Development.
-
Jansolo #1
Bit of a headache
Hi all,
I have found this bit of javascript to validate a users form input, but the
problem is that it does it in steps - ie it will check the name and if that
isn't present it will stop the form and display just the name error.
However I want it to display all the errors in one go (so if the name AND the
email is left blank, it will display both errors at the same time!). I am sure
it has to do with where you place the return false value but after an hour of
mucking about I just don't seem to be able to get it to work.
Here is the script:
function checkForm() {
name = document.getElementById("name").value;
email = document.getElementById("email").value;
comment = document.getElementById("comment").value;
if (name == "") {
hideAllErrors();
document.getElementById("nameError").style.display = "inline";
document.getElementById("name").select();
document.getElementById("name").focus();
return false;
} else if (email == "") {
hideAllErrors();
document.getElementById("emailError").style.displa y = "inline";
document.getElementById("email").select();
document.getElementById("email").focus();
return false;
} else if (comment == "") {
hideAllErrors();
document.getElementById("commentError").style.disp lay = "inline";
document.getElementById("comment").select();
document.getElementById("comment").focus();
return false;
}
return true;
}
function hideAllErrors() {
document.getElementById("nameError").style.display = "none"
document.getElementById("emailError").style.displa y = "none"
document.getElementById("commentError").style.disp lay = "none"
}
Jansolo Guest
-
transform.rotation gives me headache
Hello Im working with an Adventure game like Grim fandango. Currently im working on this script; when you get close to an interactive obejct,... -
Impersonation headache
I have been fighting with impersonation for quite sometime now and now matter what I have tried it just won't work. I am trying to get... -
Regex headache
I am having a regex nightmare and can't see the wood for the trees. I want to extract data from an HTML file. I have been using the file() command... -
gradient headache
Does any body see a problem with this? I get nothing. I want a triangle with blue in the lower right corner fading to transparent at the... -
Web Service headache
Hi there, I am working on a web service, which was going fine until this morning. Both it and my test client app (a simple web app) are running... -
Deaf Web Designer #2
Re: Bit of a headache
can you also post a example page, where we can take a look at js and html work together. it is important that you also show us html source page, just point us to your URL address and we go from there.
Deaf Web Designer Guest
-
Jansolo #3
Re: Bit of a headache
Hi there,
The URL is:
[url]http://www.names4design.co.uk/test.htm[/url]
Jansolo Guest
-
delaneypub #4
Re: Bit of a headache
In your checkForm function, your use of "else if" will bypass any of the checks
below tonce any of them is true. If name == "" is true, then it won't even
check email and comment. Replace the "else if"s with if. Also, "return" will
cause processing of the function to stop the first time it's encountered. So,
you need to set a flag if any of the checks find an error, and then only
"return false" at the very end if there are errors, else "return true"
delaneypub Guest
-
Deaf Web Designer #5
Re: Bit of a headache
I think you need to add a ';' (one of each) in the following script code as
follows below:
Your code as shown earlier:
From here:
document.getElementById("nameError").style.display = "none"
document.getElementById("emailError").style.displa y = "none"
document.getElementById("commentError").style.disp lay = "none"
To here:
document.getElementById("nameError").style.display = "none";
document.getElementById("emailError").style.displa y = "none";
document.getElementById("commentError").style.disp lay = "none";
I will take a look at Elaine's quick advice. Let us know if that works with
';' at end of those three codes.
Thanks in advance, DWD
Deaf Web Designer Guest



Reply With Quote

