Home > WebEOC > Admin Guide > Board Building Tips > Capture Parent Data in a Child Table

Capture Parent Data in a Child Table

Table of contents

There are two ways in which to capture parent data and input it into a child table. An example of each method follows below.

Example 1

In the first example, the selected option of a foreign key select list is captured. Proceed as follows:

  1. Place your foreign key tag inside a span with the id of foreign_key. For example:
    <span id="foreign_key"> <foreignkey table="Parent Table" type="select">  <eocfield name="parent" type="fk" table="Parent Table"></eocfield> </foreignkey> </span>

  2. If you do not want the field to show, add a new input field and make it hidden.The script fills the value from the parent. For example:
    <input type="hidden" size="40" value="" name="child1" required="false"></input>

  3. Reference the ID and the target child field in your JavaScript. For example:

<script type="text/javascript"> 
function captureParentData() 
{ 
var TheForeignKey= document.getElementById('foreign_key').getElementsByTagName('select')[0].options[document.getElementById('foreign_key').getElementsByTagName('select')[0].options.selectedIndex].text; document.forms[0].[childfieldgoeshere].value= TheForeignKey; 
}
function SetSubmitHandler()
{
document.forms[0].onsubmit = captureParentData;
}
window.onload = SetSubmitHandler;
</script>

Example 2

In this example, the value of a parent record foreign key that is not a select list is captured.

  1. Place a span around the <foreignkey> (just the <eocfield> element) on your child input with the id of foreign_key.
    <foreignkey table="Parent Table"><span id="foreign_key"><eocfield name="parent" type="fk" table="Parent Table"></eocfield></span></foreignkey>

  2. If you do not want the field to show, add a new input field and make it hidden. The script fills the value from the parent. For example:
    <input type="hidden" size="40" value="" name="child1" required="false"></input>

  3. Reference the ID and the target child field in your JavaScript. For example:

<script type="text/javascript">
document.forms[0].child1.value = document.getElementById('foreign_key').innerHTML;
</script>

The <eocfield name="child1" type="rl" table="Child Table" /> populates with the parent field data.

You must to post a comment.
Last modified

Tags

Classifications

This page has no classifications.