I have a PHP form in which i use java script to get birth date value from a calendar, then i wrote a onchange java script to calculate age from the value of the textbox and display it in another textbox.. but onchange function is not working...
This is the textbox code to get the birth date from calendar from external javascript that i downloaded from some site.. this works fine.. it displays selected date from calendar in the textbox..
<input id="birthdate" name="birthdate" type="text" size="12" maxlength="10" readonly="readonly" onChange="UpdateAge();" />
<script language="JavaScript">
new tcal ({
// form name
'formname': 'reg',
// input name
'controlname': 'birthdate'
});
this is the function to calculate age..
<script type="text/javascript">
function UpdateAge(){
var bdate = document.getElementById('birthdate').value;
var cdate = date('d-m-Y');
var info = (strtotime($cdate)-strtotime($bdate))/(24*60*60*365);
alert("hi");
document.getElementById('age').value = info;
}
</script>
but nothing changes in the second textbox.. this is code of second textbox..
<input name="age" type="text" id="age" size="5" maxlength="2" />
pls help me with a solution.. thanks in advance..
UpdateAge()function seem to contain PHP code. PHP codes runs on the server, javascript on the client. This won't work the way you think.