Set text-cursor position in a textarea

After refocusing the textarea with txtarea.focus(), add this line: txtarea.selectionEnd= end + 7; That will set the cursor seven positions ahead of where it was previously, which will take [b][/b] into account. Example document.getElementById(‘bold’).addEventListener(‘click’, boldText); function boldText() { var txtarea = document.getElementById(“editor_area”); var start = txtarea.selectionStart; var end = txtarea.selectionEnd; var sel = txtarea.value.substring(start, end); … Read more

Copying text of textarea in clipboard when button is clicked

You need to use select() to selecting text of textarea and use execCommand(‘copy’) to coping selected text. Its work in upper version of browsers. $(“button”).click(function(){ $(“textarea”).select(); document.execCommand(‘copy’); }); Also you can do this work without jquery as shown in bottom document.querySelector(“button”).onclick = function(){ document.querySelector(“textarea”).select(); document.execCommand(‘copy’); } document.querySelector(“button”).onclick = function(){ document.querySelector(“textarea”).select(); document.execCommand(‘copy’); }; <button>Select</button> <br/> <textarea></textarea>

CSS Styling text areas like notebook-look

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 Line 5 Line 6 Line 7 Line n </textarea> Or … Read more

How to clear textarea on click?

Your JavaScript: function clearContents(element) { element.value=””; } And your HTML: <textarea onfocus=”clearContents(this);”>Please describe why</textarea> I assume you’ll want to make this a little more robust, so as to not wipe user input when focusing a second time. Here are five related discussions & articles. And here’s the (much better) idea that David Dorward refers to … Read more

Get each line from textarea

You will want to look into the nl2br() function along with the trim(). The nl2br() will insert <br /> before the newline character (\n) and the trim() will remove any ending \n or whitespace characters. $text = trim($_POST[‘textareaname’]); // remove the last \n or whitespace character $text = nl2br($text); // insert <br /> before \n … Read more

Why isn’t this textarea focusing with .focus()?

A mouse-click on a focusable element raises events in the following order: mousedown focus mouseup click So, here’s what’s happening: mousedown is raised by <a> your event handler attempts to focus the <textarea> the default event behavior of mousedown tries to focus <a> (which takes focus from the <textarea>) Here’s a demo illustrating this behavior: … Read more

Get textarea text with JavaScript or jQuery

Reading the <textarea>‘s content: var text1 = document.getElementById(‘myTextArea’).value; // plain JavaScript var text2 = $(“#myTextArea”).val(); // jQuery Writing to the <textarea>: document.getElementById(‘myTextArea’).value=”new value”; // plain JavaScript $(“#myTextArea”).val(‘new value’); // jQuery See demo JSFiddle here. Do not use .html() or .innerHTML! jQuery’s .html() and JavaScript’s .innerHTML should not be used, as they do not pick up … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)