I want to fill out a form when opening a page (it's a page where you edit your profile information).
Here is my code:
<head>
    <script type="text/javascript">
        function addValues() {
            document.getElementById("datePicker").value = ViewBag.b.DateOfBirth.ToShortDateString();
            document.getElementById("name").value = ViewBag.b.Username;
            document.getElementById("username").value = ViewBag.b.Username;
            document.getElementById("password").value = ViewBag.b.Password;
            document.getElementById("lastname").value = ViewBag.b.Lastname;
        }
    </script>
</head>
<body onload="addValues()">
    <h2>EditProfile</h2>
    <form action="~/Authentication/EditProfile" method="post">
        <table>
            <tr>
                <td>Username:</td>
                <td><input type="text" name="username" id="username" /></td>
            </tr>
            <tr>
                <td>Password:</td>
                <td><input type="text" name="password" /></td>
            </tr>
            <tr>
                <td>Name:</td>
                <td><input type="text" name="name" id="name" /></td>
            </tr>
            <tr>
                <td>Last name:</td>
                <td><input type="text" name="lastname" /></td>
            </tr>
            <tr>
                <td>Date of birth:</td>
                <td><input type="date" name="dateofbirth" id="datePicker" /></td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="submit" value="Save" />
                </td>
            </tr>
        </table>
    </form>
</body>
When loading a page, it doesn't fill out the information, and I can't find the mistake.
Is there a better way of doing this?
The rendered JavaScript looks like:
function addValues() {
    document.getElementById("datePicker").value = 11.9.2001. 00:00:00;
    document.getElementById("name").value = Mirko;
    document.getElementById("username").value = micro;
    document.getElementById("password").value = 123456789;
    document.getElementById("lastname").value = Mijanovic;
}
 
     
    