while (re.test(str))
str = str.replace(re, '$1.$2$3')
str += (arr.length 1) ? (',' + arr[1]) : ''
elm.value = str
}
</snip>
It works as I expected, except that after the function finished its
execution the cursor moves to the end of the textfield. So if I want
to insert two or more characters, the rest of it goes to the end of
textfield.
How I determine the position of the cursor in the textfield before
executing the regex?
I wonder how to get/set the caret position of a textfield. I dont wanna paste something, but only set the caret position. With firefox I can do this stuff: textfield.startSelection = pos;With IE I dont have a plan how to solve.
I have a floating div that stays at the bottom of the browser window while the user scrolls down a long page. The div reads "scroll down for more". How can I determine the current position of the div in relation to the top of the page, not the top of the browser window. I need to determine this because I would like to hide the div when the user scrolls to the top of the last page. I have looked at offsetParent, offsetHeight, scrollHeight, etc.
I have the code for everything except determining the position of the div, or the distance of the div from the top of the page.
I have a floating div that stays at the bottom of the browser window while the user scrolls down a long page. The div reads "scroll down for more". How can I determine the current position of the div in relation to the top of the page, not the top of the browser window. I need to determine this because I would like to hide the div when the user scrolls to the top of the last page. I have looked at offsetParent, offsetHeight, scrollHeight, etc.
I have the code for everything except determining the position of the div, or the distance of the div from the top of the page.
I was editing some javascript code yesterday that happened to use jquery. Part of the code selected two elements via jquery. Then the original author used nodeIndex to determine the position of each of these nodes in their parents. I could not find any documentation on nodeIndex on the jQuery site or anywhere else on the internet. It seemed to work in IE8, but I did not see the property from FireBug in FireFox 3.5. So I removed the call to nodeIndex and used a for loop to calculate my own equivalent of the nodeIndex. Is nodeIndex officially supported or meant for internal use? Is it documented anywhere? [URL]
I have created a nice blog form for my users and I would like them to be able to use some aspects of HTML code that I have styled and they can utilise. The way I have this set up at the moment is, much like th reply boxes here, they can click on a button and the code (such as ) is automatically added to the textarea. The problem I have at the moment is that the cursor goes to the end of the content written so far and places whatever they have clicked at the end. I would like to be able to detect the cursor position and then they can add the various tags where they want them.
Also, is there a way I can get the cursor to automatically sit between the opening and closing tags that are generated (as can be seen here)??
function writeCodeTag(code) { var cache = document.getElementById('f').article.value; this.code = code; document.getElementById('f').article.value = cache + code; document.getElementById('f').article.focus(); }
This function adds the various code tags to the textarea... I have the same sort of thing for smilies.
If the user presses enter and their cursor is in the middle of a <p>, i want to insert a <br> tag. If their cursor is at the end of the <p> tag's innerHTML, then i want to insert a new <p> tag.
I can insert both tags as I need, but I can't find a way to get the position of the cursor relative to its containing tag (just assuming there's no other markup in the <p>'s innerHTML, so that selection.parentElement() will return the <p> tag).
How to add a function that will add some text in textarea, when someone clicks on button, where the cursor is?(Like here, on daniweb textareas!)eg. There is bold button! The user clicks on it, and the text "[BOLD][/BOLD]" writes where curser/caret is. Cursor/caret (|) is focused between these two elements "[BOLD]cursor/caret (|)[/BOLD]"
I need to control the cursor position in a textbox to do this, does anyone know how to place the cursor in the textbox at a particular position
The functionality I am looking for... Excel provides data entry help based on previous entries i.e. if in a previous cell in a column I entered "Jim Bob" then the next cell I type a "J" Excel provides help by showing "Jim Bob" in a way that allows me to pick it or keep typing. This is the kind of functionality I am trying to get using JS.
In the code below I create an array of previous entries by the user over the last 45 days this all comes from a DB but that's not important here. When the user enters a key in the textbox I can pop the text box with a matching value from the array, only up to the chars entered.
The Problem or Question: Is there a way to place the curser back into the last position and highlight the remaining part of the match from the array?
This is really hard to explain but if you ever used Excel you may have an idea of what I am trying to do. Code:
Is there a way to read a position of the cursor in the textarea window form? In the place showed by the cursor there should be placed any text or html tags? (when clicking on a button). I know that it's possible to write in addition to the content of the window but can you put anything to the middle of the text?
I'm using contentEditable divs. I want to have a button a person can press, a modal window appears, some text from the modal window is selected, then it is to be inserted into the contentEditable div in the location the cursor was at before pressing the button. So how can I save that spot so I can insert there?
I am currently working on a small script that allows people to insert BB-codes to edit their text. They are able to click a button (for example underline) and then the bb-code will appear at the end of the textfield-value.How can i retrieve the current position of the cursor within the textarea and then parse the bb-code within?
how can i fix this to work correctly in ie7 (and preferably ie6)this is what's supposed to happen: in a text field, as a uk postcode is typed in, once the user has typed in enough to know where the space in the postcode should be it's being placed in there for them automatically.
In IE it is a simple matter of: range.text += text; but I am having great difficulty figuring it out for FF.I have looked online for hours but the only solutions that I can find are to do with inserting text into textareas which supply you with nice 'selectionStart', 'selectionEnd' properties. Using a textarea would be useless for my purposes and a div element does not have such properties. An implementation in this case I am thinking would rely solely on the range object for the necesary selection / cursor position information, but I cannot figure out how to do this using the FF/W3C Range object.What I'm basically doing is trying to enable the user to paste unformatted (plain) text into a contenteditable zone for a WYSIWYG editor. I have got it working in IE, but FF is a whole other kettle of fish for this particular issue.
I've got a text area called Notes in a form called frmMain.
And I've got a JavaScript function.
Within the JavaScript function what code can I use to move the cursor to the text area field and specifically within that field I'd like the cursor to be exactly 10 characters into the field?
I am looking to be able to insert some text into a text box on a form without replacing the contents and so that preferably it appears at the cursor position.
The need is in a content management system, I want to be able to insert the code for an image, from a drop down menu listing the images, into the textbox containing that areas content.
I'm looking for a function that I can use which will do the following when the mouse cursor is in a textarea:
know which textarea to work with based on current cursor position (not sure if this possible, couldn't find examples) - i.e. just 1 'Bold' button to operate on multiple textareas.
insert tag or tags (i.e. ,[image]) at cursor position, if text is selected then insert tags around text selection.