|
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?'
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.