Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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?

irt.org | Knowledge Base | JavaScript | Form 5 | Q292 [ previous next ]

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?

<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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.