Set cursor to specific position on specific line in a textarea

I’ve updated your fiddle see: http://jsfiddle.net/eghpf/2/ I’ve added var currentPosition which is used in this method function setSelectionRange(input, selectionStart, selectionEnd) { if (input.setSelectionRange) { input.focus(); input.setSelectionRange(selectionStart, selectionEnd); } else if (input.createTextRange) { var range = input.createTextRange(); range.collapse(true); range.moveEnd(‘character’, selectionEnd); range.moveStart(‘character’, selectionStart); range.select(); } } Which comes from this jQuery Set Cursor Position in Text Area … Read more

How to set maxlength attribute on h:inputTextarea

HTML5 + JSF 2.2+ If you’re using HTML5 and JSF 2.2+, specify it as a passthrough attribute. <html … xmlns:a=”http://xmlns.jcp.org/jsf/passthrough”> <h:inputTextarea value=”#{bean.text}” a:maxlength=”2000″ /> HTML4 If you’re on HTML4, then it’s already not supported by HTML itself. It’s only supported on <input> element, not on <textarea> element. That’s also why there’s no such attribute on … Read more

Get value from text area [duplicate]

Vanilla JS document.getElementById(“textareaID”).value jQuery $(“#textareaID”).val() Cannot do the other way round (it’s always good to know what you’re doing) document.getElementById(“textareaID”).value() // –> TypeError: Property ‘value’ of object #<HTMLTextAreaElement> is not a function jQuery: $(“#textareaID”).value // –> undefined

Get the offset position of the caret in a textarea in pixels [duplicate]

You can create a separate (invisible) element and fill it with textarea content from start to the cursor position. Textarea and the “clone” should have matching CSS (font properties, padding/margin/border and width). Then stack these elements on top of each other. Let me start with a working example, then walk through the code: http://jsfiddle.net/g7rBk/ Updated … Read more