Here is a simple example. Say we have a function that checks if a question is visible. If it is visible does it have content. Then it returns true or falseinforms the user with an error message.
</syntaxhighlight>
Say we reuse this code about 25 times in our Form. Then the requirement changes and we need to extend the functionality to also check if there are only numbers in the box. We now have 25 functions to update, not just this one. This useful validation function uses quite a few lines of code. It can be made far more reusable by doing the following.
This useful validation === Step 1 - Create a function uses quite a few lines of code. It could be reusable by doing the following.===
</syntaxhighlight>
=== Step 2 - Use parameters ===
<syntaxhighlight lang="javascript">
function fn_ValidateFieldIfShown( strTableId, strField, strMessage){
if (document.getElementById(strTableId).style.display == 'inline-table'){
if (document.getElementById(strField).value.length == 0){
</syntaxhighlight>
=== Step 3 - Usage ===
<syntaxhighlight lang="javascript">
fn_ValidateFieldIfShown( 'tableid_1', 'strCDA_X_field_0_1', 'Error in question 1');
</syntaxhighlight>
Yes it may add some overhead to your development as you start to use this practice, however it can save hours and hours of your development in the future and make your code far easier for others to manage.
[[Category:Module Specific:Form Management]]
[[Category:Topic:JavaScript]]