[英]PHP onchange() javascript not working
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... 我有一个PHP表单,其中我使用Java脚本从日历中获取出生日期的值,然后编写了一个onchange Java脚本以从文本框的值计算年龄并将其显示在另一个文本框中..但是onchange函数不起作用...
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.. 这是文本框代码,可从我从某个网站下载的外部javascript中的日历中获取出生日期。此方法工作正常。.它在文本框中显示日历中的选定日期。
<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.. 请帮我一个解决方案..预先感谢..
(strtotime($cdate)-strtotime($bdate))
This is not Javascript code . 这不是Javascript代码 。 You have to find a library that can perform the same treatment than PHP's strtotime
您必须找到一个可以执行与PHP的strtotime
相同的处理的库
Function UpdateAge()
has got PHP code 函数UpdateAge()
已获取PHP代码
(strtotime($cdate)-strtotime($bdate))/(24*60*60*365);
Which is invalid JS so I wouldn't work on client. 这是无效的JS,所以我不会在客户端上工作。 PHP runs on server and JS runs on client. PHP在服务器上运行,而JS在客户端上运行。
strtotime is has said before strtotime is not a javascript function. 在strtotime不是javascript函数之前就已经说过strtotime。 It's a PHP function. 这是一个PHP函数。 Take look at Date object and its parse method : http://www.w3schools.com/jsref/jsref_parse.asp 看一下Date对象及其解析方法: http : //www.w3schools.com/jsref/jsref_parse.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.