Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q292 How can I validate a form and if necessary prompt for the proper values, and then still validate the new input before submitting the form?

You are here: irt.org | FAQ | JavaScript | Form | 5 | Q292 [ previous next ]

<SCRIPT LANGUAGE="JavaScript"><!--
function validate() {
    if (document.myform.mytext.value.indexOf('@') > -1)
        return true;  // simple check for @ within the form field
    else {
        // prompt for alternative value
        document.myform.mytext.value = prompt('include a @ dummy',document.myform.mytext.value);
        setTimeout('document.myform.mybutton.click()',100);
        return false;
    }
}
//--></SCRIPT>

<FORM NAME="myform" onSubmit="return validate()">
<INPUT TYPE="TEXT" NAME="mytext">
<INPUT TYPE="SUBMIT" NAME="mybutton">
</FORM>

Feedback on 'Q292 How can I validate a form and if necessary prompt for the proper values, and then still validate the new input before submitting the form?'

©2018 Martin Webb