Button text insert

They have: 21 posts

Joined: Nov 2004

I have a form as shown below.

<form action="">
<input onclick="document.selection.createRange().text='textofsomesort'" type="button" value="button"><br>
<textarea cols="20" rows="10"></textarea><br>
<input type="submit">
<input type="Reset">
</form>
'

The objective is to insert text (pre-defined only where it says 'textofsomesort') into the textarea wherever the cursor is sitting.

The present "onclick" will only work if some existing text is selected in the text area. I need it to work without selecting anything.

Has anybody got a simple solution to this?

The thinking behind this is that the button's 'textofsomesort' is database input and there could be several buttons or only one.

Hope someone can help.

thanks - Ted

He has: 1,380 posts

Joined: Feb 2002

You can put text content inside the some content fields.

Is that what you're trying to do?

They have: 21 posts

Joined: Nov 2004

No. The input from database will replace textofsomesort in text='textofsomesort'. When the button is clicked, then the text will go into the textarea.

Try the form. Type in and text and click the button. What ever text you type will be replaced by "textofsomesort".

The problem is not getting text into the text by selection but by just clicking. So the code

onclick="document.selection.createRange().'

is the problem.

- Ted

They have: 21 posts

Joined: Nov 2004

Found something that does it.Smiling

&lt;script language="JavaScript"&gt;
function InsertText(input, insTexte) {input.value += insTexte;}
&lt;/script&gt;
<form action="" name="form">
<input type=button onClick="javascript:InsertText(document.form.Text1,'ccccc');" value="button"><br>
<textarea name="Text1" Rows=5 Cols=20></textarea><br>
<input type="submit">
<input type="Reset">
</form>
'

thanks - Ted

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.