All,
... What is difficult is troubleshooting Javascript!
I develop in Firefox with the Firebug plugin. It really doesnt get much better.
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.
What about something like this?
Code:
function verOrderForm(){
anyerrors=false;
ok=getUserName(document.getElementById('username').value);
anyerrors=(!ok ? true : anyerrors);
ok=uidComplete(document.getElementById('uid').value);
anyerrors=(!ok ? true : anyerrors);
// ... do the same for all validation
if (anyerrors){
alert('No go Jack!')
return false;
} else {
return true;
}
}
You would need to mod this, as so, though
Code:
function uidComplete(uid)
{
var obj = document.getElementById('username_help');
eval(uid.response); // Executing the response from Ajax as Javascript code
if (uid.response != '1'){
document.getElementById("username_help").innerHTML = '<img src="images/check.jpg" alt="" /><br />';
return true;
} else
{
document.getElementById("username_help").innerHTML = '<img src="images/info.jpg" alt="" width="25" height="24" /><br /> That username already exists. Please choose another.';
return false;
}
}
Arrays passed to the function? Sure. More complicated, and would benefit by better naming conventions. IE:
Code:
<input type="text" id="validate_username" name="username" class="form" style="margin-left:12px;" onblur="ver_username(this.id);" />
<input type="text" id="validate_firstname" name="firstname" class="form" style="margin-left:12px; " onblur="return ver_firstname(this.id);"><br /><br /></td>
With that, each routine would strip the validate_ off the id, get value with getElementById, check, and write to help_firstname, or help_username, which I think you are already naming.
you could then on submit loop through all the form elements, check those that start with validate, and run the corresponding subroutine by replacing the validate_ with ver_ and running it.
Did I lose you?
If that is of interest, I can elaborate, but I thing the scheme I have above is pretty simple and will do what you want.
FYI: Be aware that this does not work on all browsers.
document.contact.state.value
This is the "safe" syntax:
document.contact.state.options[document.contact.state.selectedIndex].value