Splitting Up First Name and Last Name
A tactic that will allow me to create a single full name field and break the value up into first name and last name
by kshep92
HTML
<input type=text id=fullName placeholder="Full name"/> <input type=button value="Get Name" id=button /><br />
<p>
<input type=text id=firstName placeholder="First name"/> <br />
<input type=text id=lastName placeholder="Last name"/> <br />
</p>
JavaScript
(function() {
$("#button").click(function() {
var fullName = $("#fullName").val();
var firstName = fullName.substr(0, fullName.indexOf(' '));
var lastName = fullName.substr(fullName.indexOf(' ')+1, fullName.length);
$("#firstName").val(firstName);
$("#lastName").val(lastName);
});
$("#fullName").keyup(function() {
$("#button").trigger("click");
});
})();