Reputation: 129
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..
Upvotes: 0
Views: 639
Reputation: 21233
Function UpdateAge()
has got PHP code
(strtotime($cdate)-strtotime($bdate))/(24*60*60*365);
Which is invalid JS so I wouldn't work on client. PHP runs on server and JS runs on client.
Upvotes: 2
Reputation: 7133
strtotime is has said before strtotime is not a javascript function. It's a PHP function. Take look at Date object and its parse method : http://www.w3schools.com/jsref/jsref_parse.asp
Upvotes: 1
Reputation: 3153
(strtotime($cdate)-strtotime($bdate))
This is not Javascript code. You have to find a library that can perform the same treatment than PHP's strtotime
Upvotes: 3