I've been using a function in my forms to validate field values prior to submission. Pretty standard stuff. JS is really not my thing but it's very useful in these situations.
I have a <textarea> for user input on a page. The goal is to validate the input conditionally and I've modified my function as such. However, I'm obviously doing this wrong as the form is being submitted either way, which I've learned is what happens in JS when you screw up the coding for validation.
In a nutshell, if the <textarea> value is blank I don't want the form submitted and I want to return focus to the field. If the <textarea> has a value greater than "" than I want the user to confirm that they are ready for submission. Here's the function as it sits:
Code:
function validateSubmission(DT)
{
if(document.DT.DTest.value == "")
{
document.DT.DTest.focus();
return false;
}
if(document.DT.DTest.value > "")
{
if(confirm("Click 'OK' to confirm that you are done with\nthe test and would like to submit your report.\n\nOtherwise click 'Cancel' now."))
{
return true;
}
{
document.DT.DTest.focus();
return false;
}
}
}
Someone please show me where I've botched this.
Thanks in advance.