简体   繁体   English

您可以使用Javascript将日期/时间放入表单输入时吗?

[英]Can you use Javascript to put date/time into form input onload?

I am trying to put the date and time into a form field onload. 我正在尝试将日期和时间放入表单字段onload。 Am I doing something wrong here, I can't get it to work. 我在这里做错什么了吗,我无法正常工作。 Here is my code: 这是我的代码:

<HEAD>
<script type="text/javascript">
            function updateData()
            {
                var cl_dt=new Date();
                document.getElementByName("lastpost_cl").value=cl_dt;
            }
</script>
</HEAD>

<BODY onLoad="updateData();">

<form id="FormName" action="updated.php" method="post" name="FormName">
<input id="lastpost_cl" name="lastpost_cl" type="text" size="25" maxlength="255">

Use getElementById. 使用getElementById。 getElementsByName (There is an 's' after Element!) returns a collection of element(s). getElementsByName(元素后面有一个“ s”!)返回元素的集合。

getElementByName does not exist, at least not cross browser. getElementByName不存在,至少没有跨浏览器。 Use getElementById instead. 请改用getElementById。 You already have an ID that is the same, so it will work with just that change. 您已经有一个相同的ID,因此只需更改即可使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM