Stop Being Carbon

Icon

Auf den Spuren von Javascript

Bin ja fast schon selbst über mich erstaunt, dass ich es nun auch schaffe, einfache Aufgaben in JavaScript zu lösen. Ziel war es, in einem Textfeld den Cursor hinter den letzten Charakter zu stellen. Im Prinzip simpel, geholfen hat mir dabei, dass ich mich seit ein paar Tagen mit AJAX beschäftige und der Source-Code von WordPress (der Trick mit selectionStart und selectionEnd).

<html>
<head>
<title>setfocustolast(field);</title>

<script type="text/javascript" language="javascript">

function setfocustolast (TextArea)
{ 
    var cursorPos = TextArea.value.length;
    TextArea.selectionStart = cursorPos;
    TextArea.selectionEnd = cursorPos;
    TextArea.focus();
}
</script>

</head>
<body>


<span class="sec" 
onclick="setfocustolast(document.getElementById('q'));" title="setfocustolast()">SetFocusToLastCharacter</span>

<form action="" onSubmit="return false;">
<textarea id="q" name="q">Dies ist ein Textfeld</textarea>
</form>

</body>
</html>

Category: Technology

One Response

  1. Kay says:

    Und natuerlich gleich ein blog posting :)

    Danke nochmals fuer die Hilfe.

Leave a Reply

Asynchronous Google Analytics for WordPress plugin powered by WordPress Expert at minilibra.com.