Possible Duplicate:
Capitalize the first letter of string in JavaScript
This is may code so far. I would like the FIRST_Name and LAST_Name fields to capitalize the first letter and have all other letters small:
Also, I am unfamiliar with javaScript so I am not exactly sure what I am doing.
latest edit. What is wrong with this code?
<HTML>
<HEAD>
<TITLE></TITLE>
<script language="javascript" type="text/javascript">
<!--
function CheckForm()
formObj.FIRST_Name.value = titleCase(formObj.FIRST_Name.value);
formObj.LAST_Name.value = titleCase(formObj.LAST_Name.value);
function titleCase(str) {
var words = str.split(/\s+/);
for (var i=0; i<words.length; i++)
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1);
return words.join(" ");
}
{
var formObj = document.getElementById("Data");
var firstname = formObj.FIRST_Name.value;
var lastname = formObj.LAST_Name.value;
if(notEmpty(formObj.FIRST_Name, "Please enter your first name")){
if(notEmpty(formObj.LAST_Name,"Please enter your last name")){
if(titleCase(formObj.FIRST_Name)
return true;}}
return false;
}
function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
alert(helperMsg);
elem.focus(); // set the focus to this input
return false;
}
return true;
}
</script>
</HEAD>
<BODY>
<div style="background: #CCCC99">
<HR><FORM id="Data" onsubmit="return CheckForm()" action="post to server" method=post>
<P>First Name: <input type=text name=FIRST_Name maxlength=15 size=15>
Last Name: <input type=text name=LAST_Name maxlength=15 size=15></P>
<input type=submit value="Submit Products Registration Form" style="width: 220px"><input type=reset value="Reset">
</form>
</div>
</BODY>
</HTML>