|
Posted by The Natural Philosopher on 09/04/07 17:11
Captain Paralytic wrote:
> On 4 Sep, 15:38, cresh <davebow...@gmail.com> wrote:
>> Hello all,
>>
>> I'm in need of some help with inserting text into a textarea. I have
>> this (below)which actually REPLACES all text in the text area. I just
>> need the text to be added to existing text there.
>>
>> /begincode
>>
>> <head>
>> <script>
>> function InsertText(mytext){
>> document.Form.message.value = mytext;}
>>
>> </script>
>> </head>
>>
>> .....
>>
>> <input type="button" onclick="InsertText('This text is added.')"
>> value="AddText">
>> <textarea name="message" cols="60" rows="5"></textarea>
>>
>> /endcode
>>
>> This text replaces what's already in the box if I click the button.
>> What I want is to add the text when the button is clicked, not replace
>> what is already in the text area.
>>
>> Thanks very much for any assistance.
>>
>> DB
>
> At a guess, something like:
>
> function InsertText(mytext){
> document.Form.message.value = document.Form.message.value+" "+mytext;
>
>
> }
>
document.Form[0].message.value = document.Form.message[0].value+" "+mytext;
I think everyhing is an array, even when its only one element..
Or better something like
(document.getElementsByName('message'))[0].value += mytext;
Navigation:
[Reply to this message]
|