Inserting text into multine inputs

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Inserting text into multine inputs

Post by mzfp2 »

Hi I need to create JavaScript to control text in a multi-line input, basicall, when a user clicks a button, it should enter some text into the multi-line input, weherever the cursor currently is

how do I acheive this .. hopefully without writing two versions one for IE and NN

M
http://www.alljammin.com[/b]
phpfreak
Forum Commoner
Posts: 30
Joined: Fri Mar 21, 2003 10:28 am
Location: New Jersey,USA
Contact:

hi there

Post by phpfreak »

Hi I need to create JavaScript to control text in a multi-line input, basicall, when a user clicks a button, it should enter some text into the multi-line input, weherever the cursor currently is

how do I acheive this .. hopefully without writing two versions one for IE and NN

M,
I really didnt understand your question i hope the following with be of use to u:

if you are planning to write some text to any particular form element like for example you have a form called "form1" and you have a text box named "mytextbox" then you can do the following:This is a function goes to the particular textbox and writes the comment there whenever the user clickt the button Hi
-------------------------------------------------------------------------------------
<script language="JavaScript">
function testme()
{
document.form1.mytextbox.value="hi MR/Miss. M , How are u today";
}

</script>

</head>

<body>
<form name="form1">
<input type="text" name="mytextbox" id="mytextbox" size="70">
</form>

<button onClick="testme();" id="button">Hi</button>
-------------------------------------------------------------------------------------

I hope this helped , if this isnt what you want then email me i will try to help u.

bye
srinivas
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

the emoticon()-function of this board does it for IE. With a slight change mozilla is able to do so, too.

Code: Select all

<html>
	<head>
		<script type="text/javascript">
			function emoticon(text)
			&#123;
				text = ' ' + text + ' ';
				if (document.post.message.createTextRange && document.post.message.caretPos)
				&#123;
					var caretPos = document.post.message.caretPos;
					caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
					document.post.message.focus();
				&#125;
				else if(document.post.message.selectionStart)
				&#123;
					s1 = document.post.message.value.substring(0, document.post.message.selectionStart);
					s2 = document.post.message.value.substring(document.post.message.selectionStart, document.post.message.value.length);
					document.post.message.value = s1 + text + s2;
				&#125;
				else
				&#123;
					document.post.message.value  += text;
					document.post.message.focus();
				&#125;
&#125;
		</script>
	</head>
	<body>
		<form name="post">
			<textarea name="message"></textarea>
			<input type="button" onClick="javascript:emoticon('test');" value="test"/>
		</form>
	</body>
</html>
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Post by mzfp2 »

I've tried the code above, iut works fine, but it only ever adds text to the end of the textarea, even if the text caret is not at the end of the text area input, or even if text is selected

any ideas?

http://www.alljammin.com
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

with which browser?
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Post by mzfp2 »

Internet Explorer 6

even in this forum, when i click the buttons that insert UBBC codes into the text area, it always appends to the text box rather than inserting it at the caret position

thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

:oops: right, I forgot the whole
// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/vie ... 52/fid/130
function storeCaret(textEl) {
if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}
part for IE. It only applies to the emoticons on the left side for this board.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

8)
Image Image
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

my vmware evaluation key expired and once again I killed my notebook. It's always the same. "Hey, looks great, let's test it. Wow, and if I change this? gnaa.....". This time I tried to replace the "idle process". Not such a good idea :D
only sporadic IE testing for some days ;)
Ok, I could use the IE6 installed on this box ...but somehow I don't want to :twisted:
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Post by mzfp2 »

hey thanks volka :)
Post Reply