Gossamer Forum
Home : Products : DBMan : Customization :

Using JavaScript to Validate form input

Quote Reply
Using JavaScript to Validate form input
Here are the steps if for some reason you wished to use JavaScript to validate dbman form input (check for empty fields)

Code:
1. Change and Upload the attached file to your site (validate.js)

2. Modify the sub html_add_form:

a. add the line below between the <head></head> tags:
<script language="JavaScript" src="http://www.yourdomain.com/validate.js"></script>

b. change:

<form action="$db_script_url" method="POST">

to:

<form action="$db_script_url" method="POST" name="form">

c. replace:

<INPUT TYPE="SUBMIT" NAME="add_record" VALUE="Add Record">

with:

<input type="hidden" name="add_record" value="1">
<input type="button" name="button" value="Add Record" onClick="formvalidation(this.form);">


3. Repeat steps for sub html_modify_form_record (changing add_record to modify_record)

The advantage to using JavaScript is that it places some of the processing burden on the 'client-side' instead of the 'server-side' and can be used to dynamically generate/validate field input, etc.

The disadvantage is that the end-user (ie, client-side) can turn off JavaScript in the browser settings and pretty much make your form useless.