Jon
Jon

Reputation: 93

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. 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">

Upvotes: 1

Views: 1009

Answers (2)

InfinitiesLoop
InfinitiesLoop

Reputation: 14629

getElementByName does not exist, at least not cross browser. Use getElementById instead. You already have an ID that is the same, so it will work with just that change.

Upvotes: 1

edl
edl

Reputation: 3214

Use getElementById. getElementsByName (There is an 's' after Element!) returns a collection of element(s).

Upvotes: 2

Related Questions