Hello:
I have two input boxes on a form which receive the first and last name of a user. I want to be able to use charAt() to get the first letter in each box and pass it a third box on the same form. is this doable? May I request some help? I was thinking something like the function below would be the starting point --I stand correct, as it is not working.

<script type=\"text/javascript\">
var str=\"Mossa\";
<!--document.write(str.charAt(0));-->
document.write('<INPUT TYPE=text size=2 VALUE=\"str.charAt(0);\">');
var str=\"Barandao\";
document.write('<INPUT TYPE=text VALUE=\"str.charAt(0)\">');
<!--document.write(str.charAt(0));-->

</script>

Any thoughts!
Mossa

Recommended Answers

All 4 Replies

Mbarandao,

Something like this maybe:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Airshow :: Untitled</title>
<script>
onload = function(){
	var foreName = document.myForm.foreName;
	var familyName = document.myForm.familyName;
	var initials = document.myForm.initials;
	function makeInitials(){
		initials.value = foreName.value.charAt(0) + familyName.value.charAt(0);
	}
	foreName.onkeyup = familyName.onkeyup = makeInitials;//This fires makeInitials as user types
	document.myForm.onsubmit = function() {//This fires makeInitials onsubmit (some browsers may not implement onkeyup)
		//here: other onsubmit actions, eg form validation
		makeInitials();
	};
};
</script>
</head>

<body>

<form name="myForm" action="..." method="...">
	<input type="text" name="foreName" value="Mossa"><br/>
	<input type="text" name="familyName" value="Barandao"><br/>
	<input type="text" name="initials" value=""><br/>
<form>

</body>
</html>

Airshow

Mbarandao,

Something like this maybe:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Airshow :: Untitled</title>
<script>
onload = function(){
	var foreName = document.myForm.foreName;
	var familyName = document.myForm.familyName;
	var initials = document.myForm.initials;
	function makeInitials(){
		initials.value = foreName.value.charAt(0) + familyName.value.charAt(0);
	}
	foreName.onkeyup = familyName.onkeyup = makeInitials;//This fires makeInitials as user types
	document.myForm.onsubmit = function() {//This fires makeInitials onsubmit (some browsers may not implement onkeyup)
		//here: other onsubmit actions, eg form validation
		makeInitials();
	};
};
</script>
</head>

<body>

<form name="myForm" action="..." method="...">
	<input type="text" name="foreName" value="Mossa"><br/>
	<input type="text" name="familyName" value="Barandao"><br/>
	<input type="text" name="initials" value=""><br/>
<form>

</body>
</html>

Airshow

Kind of you AirShow! This is exactly what I'm attempting to achieve. Do I need to indicate somewhere on the form the preference of copying as user types. On first attempt, nothing is happening.

Your thoughts!
Mossa

Mbarandao,

Something like this maybe:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head����������������gt;Airshow :: Untitled</title>
<script>
onload = function(){
	var foreName = document.myForm.foreName;
	var familyName = document.myForm.familyName;
	var initials = document.myForm.initials;
	function makeInitials(){
		initials.value = foreName.value.charAt(0) + familyName.value.charAt(0);
	}
	foreName.onkeyup = familyName.onkeyup = makeInitials;//This fires makeInitials as user types
	document.myForm.onsubmit = function() {//This fires makeInitials onsubmit (some browsers may not implement onkeyup)
		//here: other onsubmit actions, eg form validation
		makeInitials();
	};
};
</script>
</head>

<body>

<form name="myForm" action="..." method="...">
	<input type="text" name="foreName" value="Mossa"><br/>
	<input type="text" name="familyName" value="Barandao"><br/>
	<input type="text" name="initials" value=""><br/>
<form>

</body>
</html>

Airshow

My apologizes...some oversight on my part...all is good!
Again, thank you very much!

Best,
Mossa

:cool:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.