Mogens - Thanks for the link. It really highlights the options and the IE vs. the-rest-of-the-world issues.
Another link is to the HTML5 working document at: http://www.w3.org/TR/2009/WD-html5-20090423/editing.html It is about as clear as mud when talking about the caret position. Such a thing is required to exist, but there is no description of actually using it. ----- To answer the question in an iPhoneWebDev sense (i.e. ignoring IE), here are my notes. 1. <input> and <textinput> fields have a selectionStart and selectionEnd attribute. 2. If there is no selection, the caret will appear at the selectionStart location. 3. You can set these properties from JavaScript using something like: document.getElementById('in').selectionStart=3; Now consider the following quick test: <div> <input id="in" type="text" value="This is a test" /> <input type="button" onclick=" document.getElementById('in').selectionStart=3; document.getElementById('in').selectionEnd=7; document.getElementById('in').focus();" value="Press"> </div> 4. This "works" under iOS4 on an iPhone4. By that I mean the selected region shows up with the little handles in the edit field when you press the button, and the keyboard appears. 5. On my iPad, the selection highlight and handles DO NOT appear and the caret is invisible. The keyboard does pop up. If you type a character, the (invisibly selected) selection is erased and replaced by the new character. After that the blinking caret is visible. This seems like a real bug in (at least) the older OS versions. I don't have any old iPhones handy - maybe interested observers could provide further Yes/No tests on different versions. Brian ________________________________ From: Mogens Beltoft <[email protected]> To: [email protected] Sent: Thu, November 4, 2010 11:35:26 AM Subject: Re: OK, how might one set the caret position in an input field? There is a lot of code here: http://www.webdeveloper.com/forum/archive/index.php/t-74982.html /Mogens On 04-11-2010 00:11, Brian McMillin wrote: Guys - > >Since we are discussing keyboards and input fields in general, here >is >a question: > >Suppose you have an <input> field that does not have the focus. The >system keyboard is not visible. > >Now you have some JavaScript that needs to give the focus to that ><input> element so the user can make some changes. > >How can the JavaScript force the input cursor (caret) to a >particular >location in the field? > >I am sort-of trying to emulate the editing capability that iOS >provides when the user drags the cursor around. In my case, I just >want to start the cursor in a logical location (instead of the end), >and then hand control to the iOS editing. > >A variant of this would be causing a word in the text field to be >selected (with the user handles for moving the selection) when the >field gets the focus and the keyboard pops up. > > >Does anyone know how to achieve these things programmatically? > >Thanks for any thoughts... > >Brian > > > > > >-- >You received this message because you are subscribed to the Google >Groups >"iPhoneWebDev" group. >To post to this group, send email to [email protected]. >To unsubscribe from this group, send email to >[email protected]. >For more options, visit this group at >http://groups.google.com/group/iphonewebdev?hl=en. > -- You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en. -- You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en.
