Expand my Community achievements bar.

Age Calculation From DOB - AGAIN

Avatar

Former Community Member
I have read a ton of different ways to get an age calculation to work, I think that I have the JavaScript part down but my problem is that I can not get the data to show up in the age text field.<br />First field is DOB. (Patient Date of Birth)<br />Second field is TreatDate. (the date of treatment)<br />Third field is Age. (Patient age at time of treatment)<br />I placed the calculation in the click event of the Age field intending to have the age populate after DOB and TreatDate are entered and the user clicks in the Age field. (I tried to get the calcualtion to kick off with other events but nothing worked.) I tested by changeing the script type to FormCalc from JavaScript, as soon as I click in the field with formCalc it warns me that there is a problem. So I assume that the event is correct. Here is one that I tried, the following shows the XML for the field and the JavaScript contained within it, I really think that my problem is in getting the data to output to the page on click. <br />// slashes were added for this forum so that it would come out right. <br /><br />// <field access="readOnly" h="9.525mm" name="Age" relevant="-print" w="15.875mm" x="187.325mm"><br />// <ui><br />// <numericEdit><br />// <border><br />// <?templateDesigner StyleID aped3?><br />// <edge stroke="lowered"/><br />// </border><br />// <margin/><br />// </numericEdit><br />// </ui><br />// <font typeface="arial"/><br />// <margin bottomInset="1mm" leftInset="1mm" rightInset="1mm" topInset="1mm"/><br />// <para vAlign="middle"/><br />// <caption reserve="7.5869mm"><br />// <font typeface="arial"/><br />// <para vAlign="middle"/><br />// <value><br />// <text>Age</text><br />// </value><br />// </caption><br /> <br />// <?templateDesigner ScriptInitializers initialize::lang=JavaScript;click::lang=JavaScript;?><br />// <value><br />// <integer/><br />// </value><br />// <format><br />// <picture>99999</picture><br />// </format><br />// <bind><br />// <picture>99999</picture><br />// </bind><br />// <event activity="click"><br />// <script contentType="application/x-javascript"><br /> <br />//var date1 = New Date(getField("DOB").value);<br />//var date2 = New Date(getField("TreatDate").value);<br />//msPerYear = 365*24*60*60*1000;<br />//var result = Math.floor((date2-date1)/msPerYear);<br /><br />//</script><br />// </event><br /><br />// </field><br /><br />The field is there but when I enter DOB and TreatDate then click in the field I get nothing. <br />I then tried it this way basing it on the working "today's date" box that I created elsewhere in the form. <br /><br />// <field h="9.525mm" locale="ambient" name="Age" w="15.875mm" x="187.325mm"><br />// <ui><br />// <numericEdit><br />// <border><br /> <br />// <edge stroke="lowered"/><br />// </border><br />// <margin/><br />// </numericEdit><br />// </ui><br />// <font typeface="arial"/><br />// <margin bottomInset="1mm" leftInset="1mm" rightInset="1mm" topInset="1mm"/><br />// <para vAlign="middle"/><br /> <br />// <caption reserve="7.5869mm"><br />// <font typeface="arial"/><br />// <para vAlign="middle"/><br />// <value><br />// <text>Age</text><br />// </value><br />// </caption><br /> <br />// <value><br />// <integer/><br />// </value><br /><br />// <bind match="none"><br />// <picture>99999</picture><br />// </bind><br /><br />// <event activity="click"><br />// <script contentType="application/x-javascript"><br /> <br />//var date1 = New Date(getField("DOB").value);
0 Replies