You are not logged in.

wcf.regNote.message

TheRock

Beginner

  • "TheRock" started this thread

Posts: 9

  • Send private message

1

Thursday, August 2nd 2007, 2:04am

Cursor-Position in Textfeld

Hi
verwende diesen Code zum einfügen von fettem Text etc in Textareas .:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function inputcode(text1, text2, textarea)
{
	if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
	{
		var caretPos = textarea.caretPos, temp_length = caretPos.text.length;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;
		if (temp_length == 0)
		{
			caretPos.moveStart("character", -text2.length);
			caretPos.moveEnd("character", -text2.length);
			caretPos.select();
		}
		else
		{
			textarea.focus(caretPos);
		}
	}
	else if (typeof(textarea.selectionStart) != "undefined")
	{
		var begin = textarea.value.substr(0, textarea.selectionStart);
		var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
		var end = textarea.value.substr(textarea.selectionEnd);
		var newCursorPos = textarea.selectionStart;
		var scrollPos = textarea.scrollTop;

		textarea.value = begin + text1 + selection + text2 + end;

		if (textarea.setSelectionRange)
		{
			if (selection.length == 0)
			{
				textarea.setSelectionRange(newCursorPos + text1.length, newCursorPos + text1.length);
			}
			else
			{
				textarea.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length);
			}
			textarea.focus();
		}
		textarea.scrollTop = scrollPos;
	}
	else
	{
		textarea.value += text1 + text2;
		textarea.focus(textarea.value.length - 1);
	}
}


kann mir das vielleicht jemand so umschreiben, dass ich das auch bei Textfeldern verwenden kann?
lg
TheRock

Noisy

Trainee

Posts: 65

Location: Frankfurt

  • Send private message

2

Thursday, August 2nd 2007, 2:01pm

Ersetz mal textarea mit input.

Hab zwar nicht wirklich viel Ahnung bzw. sogut wie keine Ahnung, aber das ist irgendwie plausibel ^^

TheRock

Beginner

  • "TheRock" started this thread

Posts: 9

  • Send private message

3

Thursday, August 2nd 2007, 4:35pm

danke aber geht leider auch nicht....

Prometheus

Administrator

Posts: 3,278

  • Send private message

4

Thursday, August 2nd 2007, 5:19pm

Ich bin nicht so der Fachmann für JS aber ich gehe davon aus das das in der gleichen Art wie bei einer Textarea garnicht geht mit einem Input Feld. Ich lasse mich aber auch gerne belehren wenns doch gehen sollte.
Jedwege Anfragen bitte an Technomausi oder ShaoKhan richten. Dieses Konto ist und bleibt inaktiv.

wcf.user.socialbookmarks.titel