Page 1 of 1

Inserting text into multine inputs

Posted: Mon Mar 24, 2003 10:41 am
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]

hi there

Posted: Mon Mar 24, 2003 3:48 pm
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

Posted: Mon Mar 24, 2003 6:32 pm
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>

Posted: Sun Mar 30, 2003 5:15 am
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

Posted: Sun Mar 30, 2003 6:39 am
by volka
with which browser?

Posted: Mon Mar 31, 2003 11:21 am
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

Posted: Mon Mar 31, 2003 4:40 pm
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.

Posted: Mon Mar 31, 2003 5:32 pm
by phice
8)

Posted: Mon Mar 31, 2003 6:00 pm
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:

Posted: Fri Apr 04, 2003 5:55 am
by mzfp2
hey thanks volka :)