...

View Full Version : Input into textarea



curb
06-28-2006, 07:38 PM
I'm trying create a small form when someone puts in their name, it'll show up on the textarea in a sentence. This is what I have so far:


<form onsubmit="
if(this.elements['complete_letter'].value += 'Hi I\'m ')
this.elements['complete_letter'].value += ' and I\m frustrated.';
for(var i=0;i<this.elements.length;i++)
if(this.elements[i].className.indexOf('es') != -1)
this.elements['complete_letter'].value += (i == 0 ? '' : ' ') + this.elements[i].value;return false;"
action="">

<input type=text name=msgs1 size="28" class="es">
<input type="submit"value="send"><br>
<textarea name="complete_letter" rows="20" cols="50"></textarea>
</form>

I want it to say "Hi I'm NAME HERE and I'm frustrated." but instead it's giving me "Hi I'm and I'm frustrated NAME HERE".

_Aerospace_Eng_
06-28-2006, 08:25 PM
I think you are making this more complicated than it has to be

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<script type="text/javascript">
function setValue()
{
if(document.forms[0].msgs1.value != '')
{
document.forms[0].complete_letter.value = 'Hi I\'m ' + document.forms[0].msgs1.value + ' and I\'m frustrated.';
}
else
{
alert('You must enter a value in the text box.');
}
return false;
}
</script>
</head>
<body>
<form onSubmit="return setValue()" action="">
<input type="text" name="msgs1" size="28" class="es">
<input type="submit" value="send"><br>
<textarea name="complete_letter" id="complete_letter" rows="20" cols="50"></textarea>
</form>
</body>
</html>

curb
06-28-2006, 08:48 PM
Thanks Aerospace. I'll see if I can change my learning process.

curb
06-28-2006, 09:18 PM
Sorry to ask again but how can I add something like:

My name is "NAME" and I am "AGE".

_Aerospace_Eng_
06-29-2006, 12:09 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<script type="text/javascript">
function setValue()
{
if(document.forms[0].name.value != '')
{
document.forms[0].complete_letter.value = 'Hi I\'m ' + document.forms[0].name.value + ' and I\'m frustrated and my age is ' + document.forms[0].age.value;
}
else
{
alert('You must enter a value in the text box.');
}
return false;
}
</script>
</head>
<body>
<form onSubmit="return setValue()" action="">
<input type="text" name="name" size="28" class="es"><br>
<input type="text" name="age" size="28" class="es"><br>
<input type="submit" value="send"><br>
<textarea name="complete_letter" id="complete_letter" rows="20" cols="50"></textarea>
</form>
</body>
</html>

curb
06-29-2006, 12:23 AM
Thankyou Aero.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum