Button text insert
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
kb posted this at 03:48 — 16th June 2006.
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?
Tedh posted this at 07:09 — 16th June 2006.
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
Tedh posted this at 07:55 — 16th June 2006.
They have: 21 posts
Joined: Nov 2004
Found something that does it.
<script language="JavaScript">
function InsertText(input, insTexte) {input.value += insTexte;}
</script>
<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.