Click to See Complete Forum and Search --> : pass input box value to textarea
jdawg38
12-12-2003, 07:31 PM
In a form I have the following:
1. Input Box
2. Button
3. Textarea
I have the following javascript code that takes the value I type in the input box, and puts it in the textarea when I click the button.
function put()
{
option=document.forms[0].dropdown.options[document.forms[0].dropdown.selectedIndex].text
txt=document.forms[0].number.value
txt=txt + option
document.forms[0].number.value=txt + "\n"
}
I don't know awhole lot about javascript, so I need some help tweaking the code, so that I can put multiple values in the textarea box.
Meaning I could type TEST in the input box, and click the button, then I could type TEST2 and click the button.
And in the textarea the user would see:
TEST
TEST2
I would really appreciate any suggestions. Thanks for your help.
jdawg
fredmv
12-12-2003, 07:47 PM
Welcome to the forums.document.forms[0].number.value += txt + "\n"
jdawg38
12-12-2003, 08:00 PM
Thanks!
I put the wrong bit of code in my previous message. The code I meant to put in was the following.
function putlanguage()
{
document.forms[0].languagearea.value=document.forms[0].language.value
}
The code I had in my previous message was capturing the value that a user selected from a combo box and placing it in the textbox. That bit of code worked great, It placed each successive selection from the combo box and placed it on a new line underneath all the previous selections.
I tried using the same bit of code for the input box, but it wouldn't work. I don't know enough about javascript to make it work for the input box, so I just used the function putlanguage(), shown above.
Thanks for your help!
fredmv
12-12-2003, 08:04 PM
You're welcome. Could you possibly provide the rest of the JavaScript code and possibly the HTML form?
jdawg38
12-12-2003, 08:21 PM
I guess the easiest thing to do is just provide the link and you can view the source.
Sorry for the disarray of the form. I am in the middle of redoing it so it looks a little messy.
http://www.virginiadoctors.com/adddoctor2.php
Thanks for taking the time to look at the code.
fredmv
12-12-2003, 08:32 PM
No problem. So you've tried using my previous suggestion (the += operator) and it didn't work correctly? If so, what happened? Did you recieve any errors? If so, what were they?
jdawg38
12-12-2003, 08:41 PM
Ok this is what I tried.
Input box name: language
button: onclick="putlanguage()"
Textarea name: languagearea
here is the function:
function putlanguage()
{
option=document.forms[0].language.options[document.forms[0].language.selectedIndex].text
txt=document.forms[0].languagearea.value
txt=txt + option
document.forms[0].languagearea.value +=txt + "\n"
}
The error:
Line 47:
Error: 'document .forms.0.language.options' is null or not an object
fredmv
12-12-2003, 08:44 PM
I believe the error is the result of text input elements not having an options property or selctedIndex property. Only <select> elements have those.
jdawg38
12-12-2003, 08:46 PM
I figured it was something like that, but I don't know enough about javascript to make the function suitable for an input box. I don't know if there is an "options" property alternative for an input box.
jdawg38
12-13-2003, 08:23 AM
Does anyone know of the correct property I should use instead of "options" for the input element.
Thanks for your help!
jdawg38
12-13-2003, 12:55 PM
I managed to figure it out. Here is the code I used.
function put()
{
anyname=document.forms[0].yourinputboxname.value
txt=document.forms[0].yourtextareaname.value
txt=txt + lang
document.forms[0].yourtextareaname.value=txt + "\n"
}
Thanks all for your help!
fredmv
12-13-2003, 09:48 PM
You're welcome. Good to see that you solved your problem. :D