Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Input into textarea

    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".

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I think you are making this more complicated than it has to be
    Code:
    <!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>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Aerospace. I'll see if I can change my learning process.

  • #4
    New Coder
    Join Date
    May 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry to ask again but how can I add something like:

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

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    <!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>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    New Coder
    Join Date
    May 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thankyou Aero.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •