Forum Moderators: open
I have a question about the validation of the form before submission.
What I wish to do is, when the user presses the "Submit" button, the data file will be opened to check whether his entered information is correct.
The code is as the following
<script type="text/javascript">
<!--
function ValidateForm()
{
if (document.Reg.Name.value=="")
{
alert('Please enter your Surname');
return false;
}
else if (document.Reg.USTEMail.value=="")
{
alert('Please enter your UST E-mail');
return false;
}
(else if the input data does not match the data from file
then return false)
else
{
return true;
}
}
//-->
</script>
What can I write for the bracket part?
thanks
Output the page as a dynamic page. Before the form outputs, go get the data from the database and incorporate it into the form using the server-side language of your choice. Put the database values in a variable or array so that when it's submitted, the JS operates on those values.
$name,othervars = some-server-side-function;
<script type="text/javascript">
<!--
function ValidateForm()
{
.......
else if ((name != '$name') or (some_other_vars != '$othervars')) { alert ('Data does not match'); }
}
</script>
The other is a little more complex; populate the variables via Ajax/HttpRequest.