trink Posted August 31, 2007 Share Posted August 31, 2007 Say a user has their cursor in a text box and they click a button and want to add some information in, how would I get the current position of the cursor in the textbox to add that information in to that specific place? Any help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/67482-getting-the-current-position-of-a-cursor-in-a-text-box/ Share on other sites More sharing options...
SammyGunnz Posted August 31, 2007 Share Posted August 31, 2007 Think Javascript. Link to comment https://forums.phpfreaks.com/topic/67482-getting-the-current-position-of-a-cursor-in-a-text-box/#findComment-338792 Share on other sites More sharing options...
trink Posted August 31, 2007 Author Share Posted August 31, 2007 Sir, I like the way you think, we should collaborate some time. =P Link to comment https://forums.phpfreaks.com/topic/67482-getting-the-current-position-of-a-cursor-in-a-text-box/#findComment-338926 Share on other sites More sharing options...
Fadion Posted August 31, 2007 Share Posted August 31, 2007 I did not write this javascript function by myself so i take no responsability . Hope it works anyway. With 'el' being your form control, try using: function getCaretPos(el) { var rng, ii=-1; if(typeof el.selectionStart=="number") { ii=el.selectionStart; } else if (document.selection && el.createTextRange){ rng=document.selection.createRange(); rng.collapse(true); rng.moveStart("character", -el.value.length); ii=rng.text.length; } return ii; } Link to comment https://forums.phpfreaks.com/topic/67482-getting-the-current-position-of-a-cursor-in-a-text-box/#findComment-338937 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.