textarea

Is it possible to disable textarea's multiline option?

旧街凉风 提交于 2019-12-04 23:34:08
Of course, I can use standard html text box, but I need text area for some reason. So, is it possible to disable textarea's multiline option? You can set the size of your textarea using the cols and rows attributes and make it non-resizable in CSS but you can't prevent the user from adding more than one line. Even if the area is just too small, a scrollbar will appear and let them write as many lines as they want. If you really need to get just one line, I suggest setting the rows attribute to 1 and checking if the input has a single line with Javascript. In html: <textarea name="a" cols="5"

How to count words in a textarea by jquery and return that value

一个人想着一个人 提交于 2019-12-04 23:16:52
function count(){ var val = $.trim($('textarea').val()), words = val.replace(/\s+/gi, ' ').split(' ').length, chars = val.length; if(!chars)words=0; return words; } This function always return 0? Please help. You can split the textarea value on spaces and then get the words length in it. Try this: var words = $('textarea').val().split(' '); alert(words.length);//or return words.length; working Demo text_area = $('textarea').val(); text_area.length == 0 ? 0 : text_area.trim().split(/\s+\b/).length 来源: https://stackoverflow.com/questions/23133617/how-to-count-words-in-a-textarea-by-jquery-and

Getting CodeMirror to follow a TextArea

▼魔方 西西 提交于 2019-12-04 23:15:26
问题 How can I get CodeMirror to sync with a TextArea, so that the cursor position, selection & data stay the same on the both of them? I'm using CodeMirror with MobWrite. CodeMirror only uses a textArea to read input & MobWrite can handle the selection, etc over a given TextArea, the problem is to get CodeMirror to sync with a TextArea. 回答1: Extended the ModWrite code to support CodeMirror & it works like a charm. It can also be found on GitHub. Details on the CodeMirror Group. Code dumped below

sizing a textarea with CSS vs with cols and rows

[亡魂溺海] 提交于 2019-12-04 23:07:42
What's the difference between sizing a textarea with cols and rows and sizing a textarea with height and width? <textarea id="TextArea1" cols="73" rows="12">with cols rows</textarea> <textarea id="TextArea2" style="height:200px; width:600px";>with CSS</textarea> jsFiddle cols and rows are relative to font size. height and width aren't. http://jsfiddle.net/rVUEE/1/ EDIT: Saying they are relative to "font size" is a bit too simplistic. They take into account things such as line-height and letter-spacing if explicitly set as well. The cols and rows attributes were required by HTML specifications.

Angularjs select elements from list and display in textarea

微笑、不失礼 提交于 2019-12-04 21:02:07
I have a problem with Angular and nya-select. Example array in my angular controller: vm.arrayCollection = [ { name: 'Alice', mail: 'Class A' }, { name: 'Bob', mail: 'Class B1' }, { name: 'Carl', mail: 'Class A2' }, { name: 'Daniel', mail: 'Class B2' }, { name: 'Emi', mail: 'Class A3' }, { name: 'Flank', mail: 'Class B3' }, { name: 'George', mail: 'Class C4' }, { name: 'Harry', mail: 'Class C5' } ]; I have select option element: <ol class = "nya-bs-select" ng-model = "myModel"> <li nya-bs-option="person in myController.arrayCollection"> <a> {{ person.name }} </a> </li> </ol> And second one is

JavaFX - get current word being typed in TextArea

北慕城南 提交于 2019-12-04 20:55:52
I'm trying to get the current word or partial word currently being typed in a JavaFX TextArea to pass to to a very basic AutoComplete getPredictions(String prefix); method. Right now I am using an Event Handler on KeyTyped and I'm going to track each character typed and concatenate it with the previously typed word, resetting on a space. This is going to have a lot of pitfalls I can see with AutoComplete being turned on in the middle of typing a word, getting the previous word if backspace is hit and the caret is at the end of the word again. I'm curious to see if there's an alternative

jQuery - Textarea auto grow plugin cross-browser compatible

岁酱吖の 提交于 2019-12-04 19:53:40
I need a cross-browser compatible plugin for textrea to be auto growing and shrinking when the inside text is getting written or deleted. I have tried the Elastic plugin and Padolsey autoresize ones. Both fails in Firefox 3.6. I've been using the snippet at: Autogrow script @ Javascript Bindings for the Google AppEngine Data Store Project on Google Code Just in case the URL may be down or deleted, here goes the code: (function($) { /* * Auto-growing textareas; technique ripped from Facebook */ $.fn.autogrow = function(options) { this.filter('textarea').each(function() { var $this = $(this),

how to limit number of characters in a textarea field processing php?

狂风中的少年 提交于 2019-12-04 19:37:05
问题 I am using a a textarea field in a form that is made on html and the processing is done by php. I want to limit the number of characters the user can enter in the textarea. Is there any way by which this can be done because the textarea field is then stored into a mysql database and thus i have to limit the user data according to the varchar value of the field. Any help? 回答1: You can limit this by setting maxlength attribute on textarea tag like <textarea maxlength="120"></textarea> in HTML

How to change color of text in a textarea

岁酱吖の 提交于 2019-12-04 19:27:48
I have a textarea and when I type something, for some words the color should change. For example, if the typed text is next one: He went to the market to buy an apple The "market" word should become green The "apple" word should become red This is my current code: var str = 'market'; var value = str.includes('market'); if (value == str) { document.getElementById("text").style.color = "green"; } else { document.getElementById("text").style.color = "red"; } <textarea rows="9" cols="100" id="text" onClick="changeText();"></textarea> Unfortunately, you can't add markup inside a textarea , but here

Javascript: how to get line/col caret position in textarea?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 19:21:47
I can not find the solution. I've tried to assume that count of \n symbols is the same with lines count, but sometimes this method works incorrectly (e.g. after paste text from clipboard) i've tried different jQuery plugins, but still unsuccessfully. any idea? Sélim Achour Why not just do this: Take the text content only up to selectionStart then make it an array by splitting at eol p = $('#Form_config').val().substr(0, $('#Form_config')[0].selectionStart).split("\n"); // line is the number of lines line = p.length; // col is the length of the last line col = p[p.length-1].length; The