blackcell Posted May 7, 2008 Share Posted May 7, 2008 I am wanting to send pageup and home with javascript. I am not for sure how to send keys though. Link to comment https://forums.phpfreaks.com/topic/104633-keystrokes-with-javascript/ Share on other sites More sharing options...
rarebit Posted May 7, 2008 Share Posted May 7, 2008 Have a look here Link to comment https://forums.phpfreaks.com/topic/104633-keystrokes-with-javascript/#findComment-535535 Share on other sites More sharing options...
blackcell Posted May 8, 2008 Author Share Posted May 8, 2008 I may have overlooked something but I found nothing on inserting keystrokes. Link to comment https://forums.phpfreaks.com/topic/104633-keystrokes-with-javascript/#findComment-535655 Share on other sites More sharing options...
blackcell Posted May 8, 2008 Author Share Posted May 8, 2008 Ok, maybe I should ask of something easier. I want to set focus to a textfield with text in it, but instead of the insertion point being the end of the text field I want it to be the beginning. Link to comment https://forums.phpfreaks.com/topic/104633-keystrokes-with-javascript/#findComment-536042 Share on other sites More sharing options...
bibby Posted May 11, 2008 Share Posted May 11, 2008 ah, then that'd be a Range. Here are some fns that came from quirksmode function getcaret(elm) { var caret = 0; // IE Support if (document.selection) { elm.focus (); var sel = document.selection.createRange (); sel.moveStart ('character', -elm.value.length); caret = Sel.text.length; } // Firefox support else if (elm.selectionStart || elm.selectionStart == '0') caret = elm.selectionStart; return (caret); }; function setcaret(elm, pos) { if(elm.setSelectionRange) { elm.focus(); elm.setSelectionRange(pos,pos); } else if (elm.createTextRange) { var range = elm.createTextRange(); range.collapse(true); range.moveEnd('character', pos); range.moveStart('character', pos); range.select(); } }; So your textarea might look like this to set the caret at the start when clicked. <textarea name="foo" onfocus="setcaret(this,0)">asdf asdf asdf asdf </textarea> Link to comment https://forums.phpfreaks.com/topic/104633-keystrokes-with-javascript/#findComment-538067 Share on other sites More sharing options...
blackcell Posted May 12, 2008 Author Share Posted May 12, 2008 Thanks, worked like a charm. Link to comment https://forums.phpfreaks.com/topic/104633-keystrokes-with-javascript/#findComment-539004 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.