textarea

Understanding what goes on with textarea selection with JavaScript

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 04:19:40
问题 I am working on an in-browser editor within a textarea . I have started looking for some information on dealing with textarea selection and found this jQuery plugin, fieldSelection that does some simple manipulation. However, it doesn\'t explain what\'s going on. I want to understand more on textarea selection in JavaScript, preferably with a description of both pre-DOM3 and post-DOM30 scenarios. 回答1: Start with PPK's introduction to ranges. Mozilla developer connection has info on W3C

JavaScript get TextArea input via .value or .innerHTML?

我与影子孤独终老i 提交于 2019-11-26 03:59:26
问题 Is it ok to get the value of a textarea element in JavaScript with myTextArea.value or should I use myTextArea.innerHTML ? Thank you. 回答1: You should use .value myTextArea.value 回答2: For div and span, you can use innerHTML, but for textarea use value. Please see the example below. <script language="javascript/text"> document.getElementById("spanText").innerHTML ="text"; document.getElementById("divText").innerHTML ="text"; document.getElementById("textArea").value ="text"; </script> <span id=

Highlight text inside of a textarea

戏子无情 提交于 2019-11-26 03:58:47
问题 Is it possible to highlight text inside of a textarea using javascript? Either changing the background of just a portion of the text area or making a portion of the text selected ? 回答1: Try this piece of code I wrote this morning, it will highlight a defined set of words: <html> <head> <title></title> <!-- Load jQuery --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <!-- The javascript xontaining the plugin and the code to init

What character represents a new line in a text area

懵懂的女人 提交于 2019-11-26 03:57:30
问题 Just quick one, but want to make sure I\'m catching cross platform variations. I like to convert new lines entered into a text area into a [comma], so that the output can be represented on a single line, my question... Currently, sending from google chrome, when I view the value, I find it uses \\r\\n for new lines. If I replace \\r\\n I know it will work for chrome on windows 7, but what about other platforms, are there variations on what other browsers will insert as a new line inside a

Limit number of lines in textarea and Display line count using jQuery

蹲街弑〆低调 提交于 2019-11-26 03:56:59
问题 Using jQuery I would like to: Limit the number of lines a user can enter in a textarea to a set number Have a line counter appear that updates number of lines as lines are entered Return key or /n would count as line Kudos to anyone who can help! $(document).ready(function(){ $(\'#countMe\').keydown(function(event) { // If number of lines is > X (specified by me) return false // Count number of lines/update as user enters them turn red if over limit. }); }); <form class=\"lineCount\">

Insert text into textarea at cursor position (Javascript)

假装没事ソ 提交于 2019-11-26 03:49:21
问题 I would like to create a simple function that adds text into a text area at the user\'s cursor position. It needs to be a clean function. Just the basics. I can figure out the rest. 回答1: function insertAtCursor(myField, myValue) { //IE support if (document.selection) { myField.focus(); sel = document.selection.createRange(); sel.text = myValue; } //MOZILLA and others else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField

finding “line-breaks” in textarea that is word-wrapping ARABIC text

两盒软妹~` 提交于 2019-11-26 03:39:59
问题 I have a string of text that I display in a textarea (right-to-left orientation). The user can resize the textarea dynamically (I use jquery for this) and the text will wrap as necessary. When the user hits submit, I will take that text and create an image using PHP, BUT before submitting I would like to know where the \"line-breaks\" or rather \"word-wraps\" occur. Everywhere I have looked so far only shows me how to process line-breaks on the php side. I want to make it clear that there ARE

Count characters in textarea

梦想与她 提交于 2019-11-26 03:27:40
问题 I want to count characters in a textarea, so I just made: <textarea id=\"field\" onkeyup=\"countChar(this)\"></textarea> function countChar(val){ var len = val.value.length; if (len >= 500) { val.value = val.value.substring(0, 500); } else { $(\'#charNum\').text(500 - len); } }; What\'s wrong with my piece of code? It does not work! Well, that was a newbie handwriting, need a help. 回答1: What errors are you seeing in the browser? I can understand why your code doesn't work if what you posted

How to autosize a textarea using Prototype?

放肆的年华 提交于 2019-11-26 03:17:07
问题 I\'m currently working on an internal sales application for the company I work for, and I\'ve got a form that allows the user to change the delivery address. Now I think it would look much nicer, if the textarea I\'m using for the main address details would just take up the area of the text in it, and automatically resize if the text was changed. Here\'s a screenshot of it currently. Any ideas? @Chris A good point, but there are reasons I want it to resize. I want the area it takes up to be

Format text in a <textarea>?

不羁的心 提交于 2019-11-26 02:57:24
问题 Textareas are great because of some built in functionality (scrollbars). How can I format <spans> of text inside of the <textarea> ? 回答1: If you need to customize your textarea, reproduce its behavior using another element (like a DIV) with the contenteditable attribute. It's more customizable, and a more modern approach, textarea is just for plain text content, not for rich content. <div id='fake_textarea' contenteditable></div> The scrollbars can be reproduced with the CSS overflow property