Forum Moderators: open
An example of how this is done can be found on Amazon.com. If there is a problem with a form, the page refreshes and a box is displayed above the form marked Important Message and then all the problems with the form are displayed beneath the actual form field. How the heck is this accomplished? I tried viewing source and wasn't able to really decipher what was going on... HELP PLEASE!
When / if there are any problems, the box is displayed. Including details about what's actually wrong is easy too, but depends upon the specific validation requirements of the form.
Is it a short form?
Can you post it?
<script type="text/javascript">document.write("<DIV style=\"position:absolute;display:none;height:200px;width:246px;border:1px solid #000000;word-wrap:break-word\" id=\"mgMain\">\n<DIV style=\"padding-left:4px;padding-right:4px;\" id=\"mgTitle\">\n\n</DIV>\n<HR size=1 style=\"margin-top:-6px;width:244px;margin-bottom:-4px\" noshade color=\"#000000\">\n<DIV style=\"margin-left:4px;padding-right:4px;padding-top:-2px;display:inline;margin-top:-2px\" id=\"mgIn\">\n\n</DIV>\n</DIV>");
function nAlert(msgTitle, msg){
msg=msg.replace(/\</g, "<");
msgTitle=msgTitle.replace(/\</g, "<");
msg=msg.replace(/\>/g, ">");
msgTitle=msgTitle.replace(/\>/g, ">");
document.getElementById("mgMain").style.display="inline";
document.getElementById("mgTitle").innerHTML="\n"+msgTitle+"\n";
document.getElementById("mgIn").innerHTML="\n"+msg+"\n";
document.getElementById("mgMain").style.left=document.body.clientWidth/2-document.getElementById("mgMain").clientWidth/1.5+"px";
document.getElementById("mgMain").style.top=document.body.clientHeight/2-document.getElementById("mgMain").clientHeight/1.5+"px";
}
window.setTimeout("nAlert('>> Invalid Input <<','That input does not match our sensors.')",3000)
</script>
(As you've been informed elsewhere..) it's a matter of running through the form's input elements, checking them against validation rules (RegExps etc), whilst building up a string that carries the details of any invalid input for the error message.
I've got customer info, then payment info and three radio buttons for different payment methods, then an additional two radio buttons for a one of the first three radio button sets, and following that of course is the comments section
That's not necessarily a lot of code.