Click Datalinks When Checkboxes are Checked
The following JavaScript is designed to check/click a datalink only if a specific checkbox is checked. This function must be called to be implemented. The easiest way to do so is by using the HTML <onclick> attribute in the <checkbox> tag.
<input type="checkbox" name="Name_of_Your_Checkbox_Field_1" onclick="checkDatalink()"/>
The above calls the function below and causes the datalink to be checked if the condition is met. If the condition is not met, the datalink is not checked.
<script type="text/javascript">
function checkDatalink()
{
if(document.forms[0].Name_of_Your_Checkbox_Field_1.checked == true)
{
document.forms[0].datalinkid.checked = true;
}
else
{
document.forms[0].datalinkid.checked = false;
}
}
</script>
Tips
-
This code only works for input views where only one datalink exists.
-
After this function is implemented correctly, you may wish to hide your datalink, depending on the design of your boards involved. To do this, use the <span> tags or the HTML <style> attribute of the <tr> or <td> tags.
-
If more than one checkbox exists and you need the datalink to be checked if either of the checkboxes are checked, you can use an OR boolean in the JavaScript if statement. The rest of the script will be the same.
if(document.forms[0].Name_of_Your_Checkbox_Field_1.checked == true || document.forms[0].Name_of_Your_Checkbox_Field_2.checked == true)