0

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

2
Contributors
4
Replies
7
Views
6 Years
Discussion Span
Last Post by Airshow
0

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

0

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.