HI,brothers There are two inputs(type=text) on a page,when i type something in the first input and then press "Enter" on the keyboard, i wanna put my cursor to the second input automatically. I then wrote a function called "enterToTab" to deal with that,as below,but it failed.Can u help me to fix my enterToTab function?Thx. function enterToTab(e){ if(e.keyCode==Event.KEY_RETURN){ e.keyCode=Event.KEY_TAB; } } Element.observe(window,''load'',function(){ $(''input1'').observe(''keydown'',enterToTab); }); I debug the code above with firebug,it shows "setting a property that has only a getter",but i don''t know how to fix... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
David Dashifen Kees
2007-Apr-17 13:15 UTC
Re: Help:How2Build enterToTab() function with prototype.js
Your better option would be to detect the enter key as you have but then to call the focus() method of the other input field. This should move the cursor. The error your getting is a result of trying to change the keyCode of the error object, which you cannot do. -- Dash -- Vin wrote:> HI,brothers > There are two inputs(type=text) on a page,when i type something in the > first input and then press "Enter" on the keyboard, i wanna put my > cursor to the second input automatically. > > I then wrote a function called "enterToTab" to deal with that,as > below,but it failed.Can u help me to fix my enterToTab function?Thx. > > function enterToTab(e){ > if(e.keyCode==Event.KEY_RETURN){ > e.keyCode=Event.KEY_TAB; > } > } > > Element.observe(window,''load'',function(){ > $(''input1'').observe(''keydown'',enterToTab); > }); > > I debug the code above with firebug,it shows "setting a property that > has only a getter",but i don''t know how to fix... > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---