textarea

JavaScript get TextArea input via .value or .innerHTML?

无人久伴 提交于 2019-11-26 14:42:45
Is it ok to get the value of a textarea element in JavaScript with myTextArea.value or should I use myTextArea.innerHTML ? Thank you. You should use .value myTextArea.value 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="spanText"></span> <div id="divText"></div> <textarea id="textArea"></textArea> One difference is that you can

Highlight text inside of a textarea

∥☆過路亽.° 提交于 2019-11-26 14:40:00
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 ? 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 the plugin --> <script type="text/javascript"> $(function() { // let's init the plugin, that we called

Find out the &#39;line&#39; (row) number of the cursor in a textarea

家住魔仙堡 提交于 2019-11-26 14:13:01
问题 I would like to find out and keep track of the 'line number' (rows) of the cursor in a textarea. (The 'bigger picture' is to parse the text on the line every time a new line is created/modified/selected, if of course the text was not pasted in. This saves parsing the whole text un-necessarily at set intervals.) There are a couple of posts on StackOverflow however none of them specifically answer my question, most questions are for cursor position in pixels or displaying lines numbers besides

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

ぐ巨炮叔叔 提交于 2019-11-26 13:25:16
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 NO LINE-BREAKS. What I have is one LONG string that will be word-wrapped in different ways based on the

Ckeditor update textarea

假如想象 提交于 2019-11-26 12:57:42
问题 I am trying to get the ckeditor working. Obviously it doesn\'t make use of the textarea so on submit the form doesn\'t submit the text in the editor. Beceause I make use of polymorphic associations etc. I can\'t make a onsubmit function to get the value of the textarea (when the form is submitted) . So I found this question: Using jQuery to grab the content from CKEditor's iframe with some very good answers. The answers posted there keep the textarea up to date. That is very nice and just

Format text in a <textarea>?

陌路散爱 提交于 2019-11-26 12:27:08
Textareas are great because of some built in functionality (scrollbars). How can I format <spans> of text inside of the <textarea> ? 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. You can use this fake textarea in a form normally, i.e: if you have to submit its content through POST

Html adding line numbers to textarea

痴心易碎 提交于 2019-11-26 12:25:41
问题 I have a textarea as in code below, how to display the line numbers on the left hand side of it. Is there a jquery plugin? <TEXTAREA name=\"program\" id=\"program\" rows=\"15\" cols=\"65\" ></TEXTAREA> 回答1: There is Lined TextArea mirror plugin for jQuery by Alan Williamson MIT License jQuery 1.3+ 回答2: You can very well try Code Mirror, which is a JavaScript library for embedding a code editor in a web page. With code lines, it has great features like Autocompletion Themes Mixed language

Cursor position in a textarea (character index, not x/y coordinates)

别说谁变了你拦得住时间么 提交于 2019-11-26 12:15:10
问题 How can I get the caret\'s position in a textarea using jQuery? I\'m looking for the cursor\'s offset from the start of the text, not for the (x, y) position. 回答1: Not jQuery, but just Javascript... var position = window.getSelection().getRangeAt(0).startOffset; 回答2: Modified BojanG's solution to work with jQuery. Tested in Chrome, FF, and IE. (function ($, undefined) { $.fn.getCursorPosition = function() { var el = $(this).get(0); var pos = 0; if('selectionStart' in el) { pos = el

CSS Styling text areas like notebook-look

我只是一个虾纸丫 提交于 2019-11-26 12:06:57
问题 It is possible to style a text area so each row have a dotted underline (like a notebook or a notes-block)? The number of lines should be fixed to lets say 10. 回答1: Here's probably what you looking for: <style type="text/css"> textarea { background: url(http://i.stack.imgur.com/ynxjD.png) repeat-y; width: 600px; height: 300px; font: normal 14px verdana; line-height: 25px; padding: 2px 10px; border: solid 1px #ddd; } </style> <textarea> Textarea with style example Line 1 Line 2 Line 3 Line 4

Twitter bootstrap - Focus on textarea inside a modal on click

孤人 提交于 2019-11-26 12:01:39
问题 Just starting to play around with bootstrap and it\'s amazing. I\'m trying to figure this out. I have a textarea for feedback inside a modal window. It works great. But I want the focus to go on the textarea when you click on the button to activate the modal. And I can\'t seem to get it working. Here is a fiddle: http://jsfiddle.net/denislexic/5JN9A/4/ Here is the code: <a class=\"btn testBtn\" data-toggle=\"modal\" href=\"#myModal\" >Launch Modal</a> <div class=\"modal hide\" id=\"myModal\">