Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There were three errors in your code, see the comments inline below:</p> <p>The year value of first option was 991 instead of 1991, might cause you to think the calculation is wrong.</p> <p>String containing date that is being assigned to birth variable has to be passed as parameter to Date() function to create a date object that can be used with the current date object below it.</p> <p>Variable milliDay was declared, then you were trying to use milliday (wrong case D).</p> <pre><code>&lt;input name= "date" type="text" readonly="readonly" /&gt; &lt;select id="Ultra" onchange="run()"&gt; &lt;option value="11/15/1991"&gt;1991-11-15&lt;/option&gt; &lt;!-- year value was 991 instead of 1991, might cause you to think the calculation is wrong --&gt; &lt;option value="10/23/1992"&gt;1992-10-23&lt;/option&gt; &lt;/select&gt;&lt;br&gt;&lt;br&gt; TextBox1&lt;br&gt; &lt;input type="text" id="srt" placeholder="get value on option select" readonly="readonly"&gt;&lt;br&gt; &lt;script type="text/javascript"&gt; function run() { var birth = new Date(document.getElementById("Ultra").value); //string containing date has to be passed as parameter to Date() function to create a date object that can be used with the current date object below var check = new Date(); var milliDay = 1000 * 60 * 60 * 24; var AgeinDay = (check - birth) / milliDay; //variable here was milliday all small case, declared above as milliDay with a capital D var ComputAge = Math.floor(AgeinDay / 365 ); var age = ComputAge / 365; document.getElementById("srt").value = age; } &lt;/script&gt; </code></pre> <p>This will return the following values assuming the first option is selected:</p> <p>age: 0.057534246575342465</p> <p>ComputAge: 21</p> <p>Are you just trying to get the age in years, or months, days hours too?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload