When working with Javascript, I have encountered a challenge. I am attempting to extract the First, Middle, and Last names from a full name input into three separate fields - Character Length, Middle Name, and Initials. At this point, I have successfully managed to determine the character length of the full name but extracting information between two spaces has proven to be a stumbling block.
// strings.js
// This script is designed to calculate the character length and initials of a given name.
// The function executes when the form is submitted.
// It calculates the values and returns false.
function formatNames() {
'use strict';
// Variables for storing Full Name, Middle Name, initials, and length:
var lengthName;
var middleName;
var yourInitials;
// Accessing the form value:
var fullName = document.getElementById('fullName').value;
// Calculate the character length:
lengthName = fullName.length;
// Extract the middle name:
// Display the character length:
document.getElementById('nameLength').value = lengthName;
// Prevent submission by returning false:
return false;
} // End of formatNames() function.
// This function adds an event listener to the form when the window loads.
function init() {
'use strict';
document.getElementById('theForm').onsubmit = formatNames;
} // End of init() function.
window.onload = init;