Forum Moderators: open

Message Too Old, No Replies

Validating the form submission by loading the data from file

         

mckingwan

9:44 am on Oct 14, 2008 (gmt 0)

10+ Year Member



Hi all~

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

rocknbil

7:03 pm on Oct 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard mckingwan, I will suggest two methods that may be useful.

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.