JavaScript Program to Display First, Middle and Last Name from Full Name

Write a JavaScript program to input full name of user and display its first, middle and last name.

Source Code
    <title>Divide first, middle, last names</title>
        function getNames()
            var fname = document.getElementById('full_name').value
            var names = fname.split(" ")
            document.write("First name: " + names[0]);
            document.write("<br>Middle name: " + names[1]);
            document.write("<br>Last name: " + names[2]);
Enter Full Name<input type="text" id="full_name"/><br/>
<input type="button" value="Submit" onclick="getNames()"/>