All,
One thing I totally dislike is doing form validation, so I thought I would spice it up a bit by doing some Ajax and instant feedback type of form. Specifically, when you enter a username, I have a function that will check to see if that username exists in the database via a XMLHTTP request in the background. Try typing in "admin" to see a return on an existing username. Really, Ajax is not so difficult. What is difficult is troubleshooting Javascript!
The other neat thing is that when you choose a state, the database is queried and only the universities for that state will appear in the next select box down. So, choose a state first and then the universities will appear for that state. I'm thinking of writing a tutorial on how I did this, if any one is interested - let me know.
For those of you who wouldn't mind giving me some constructive feedback about the form in progress, I would sincerely appreciate it, especially since it is my first attempt at Ajax.
What I'm having trouble with figuring out is how to (in Javascript) only return true with the order form when all the required fields are either correct and filled out. There must be some way to have all of those functions that I have for checking the database and returning the universities list feed into an array I can check on a submit. Any ideas? Right now the required fields validate individually, but not as a complete form.
The simple way with one function is a bunch of chained if statements (see below)...
Code:
else if(document.contact.state.value=='abc') {
document.getElementById('state_help').innerHTML = '<img src="http://glowhost.com/forums/images/info.jpg" alt="" width="25" height="24" /><br/> Please Choose a state.';
return false;
}
else {
return true;
}
and when all the conditions are met, then the form returns true and the post executes to the php script. Problem is, I have several different "separate" functions for the ajax-specific field, so how do I evaluate everything together for a post?
Here's the link:
Campus Mic
Any help is warmly appreciated,