Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / February 2007



Tip: Looking for answers? Try searching our database.

input field focus

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Will_uk - 28 Feb 2007 12:52 GMT
I am trying to return focus to a form input field.

If i use <form>.<field>.focus() the focus returns to the field but if
the field already contains a value it selects it (blacks it out).

Is it possible to focus on a input field but rather than selecting any
already inputted text, putting the cursor to the end of the field.

Cheers
Bart Van der Donck - 28 Feb 2007 15:34 GMT
> I am trying to return focus to a form input field.
> If i use <form>.<field>.focus() the focus returns
[quoted text clipped - 4 lines]
> than selecting any already inputted text, putting
> the cursor to the end of the field.

This should do the trick:

   <form>
   <input type="text" name="t" value="123">
   <input type="button" value="click" onClick="
          document.forms[0].t.focus()
          var V = document.forms[0].t.value
          document.forms[0].t.value = ''
          document.forms[0].t.value = V
          var L = (document.forms[0].t.value).length
          if (document.forms[0].t.setSelectionRange)  {
               document.forms[0].t.setSelectionRange(L, L)
          }
          else if (document.forms[0].t.createTextRange)  {
               var range = document.forms[0].t.createTextRange()
               range.collapse(true)
               range.moveEnd('character', L)
               range.moveStart('character', L)
               range.select();
          }
   ">
   </form>

Hope this helps,

--
Bart
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.