Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding text to text box 2

Status
Not open for further replies.

Andy6666uk

Programmer
Jul 11, 2001
17
GB
I want to have names on a page that, if clicked on, will be added to a list of names in a textbox.

Could you help me with the code for this?

Thanks andy
 
well, here's the simple version:

<script language=&quot;JavaScript&quot;>
<!--
var temp=&quot;&quot;;
function addemup(name){
temp=temp+name;
document.theform.thelist.value=temp;
}
// -->
</script>

<form name=&quot;theform&quot; method=&quot;post&quot; action=&quot;&quot;>
<table width=&quot;400&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td rowspan=&quot;3&quot; width=&quot;87&quot;>
<a href=&quot;#&quot; onClick=&quot;return addemup('name1')&quot;>name1<br>
</a><a href=&quot;#&quot; onClick=&quot;return addemup('name2')&quot;>name2</a><br>
<a href=&quot;#&quot; onClick=&quot;return addemup('name3')&quot;>name3</a></td>
<td rowspan=&quot;3&quot; width=&quot;267&quot; align=&quot;right&quot;>
<textarea name=&quot;thelist&quot; cols=&quot;40&quot; rows=&quot;3&quot; wrap=&quot;VIRTUAL&quot;></textarea>
</td>
</tr>
</table>
</form>
__________________________

this doesnt allow for carriage returns tho...you may need a little more help with it. ~ jsLove ;)
 
The easiest way to add a value to a textbox or textarea is:
Code:
document.theform.thelist.value=document.theform.thelist.value+name; Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
hie
Tracy, what about spaces or other delimiters?
e.g.
var delim=&quot; &quot;
document.theform.thelist.value=document.theform.thelist.value+delim+name

& andy46uk, here is how 2 insert new value into the textarea, just in case if u'll need it.. :
: <textarea id=EDITOR....
function splitEdit()
{
var sel=document.selection.createRange();
sel.collapse();
var sel_before=sel.duplicate();
var sel_after=sel.duplicate();

sel.moveToElementText(document.all.EDITOR);
sel_before.setEndPoint(&quot;StartToStart&quot;,sel);
sel_after.setEndPoint(&quot;EndToEnd&quot;,sel);

text_before=sel_before.text
text_after=sel_after.text;

}

or just
<textarea id=EDITOR></textarea>
<button id=INSERT>insert</button>

<script for=INSERT event=onclick>
EDITOR.focus();
with(document.selection.createRange())
{
collapse();// åñëè õîòèòå replace selection - óäàëèòå ýòî
text=&quot;your string&quot;
}
</script>

regards, vic
 
oops, sorry, read:
collapse();// if ya wanna replace selection - delete this string (or comment it)
regards, vic
 
I didn't mention spaces or other delimiters because I wanted to keep it simple, but that's not a problem. You can add a linefeed before the new text with:
Code:
document.theform.thelist.value=document.theform.thelist.value+&quot;\n&quot;+name;
Adding spaces would be similar. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top