Setting initial focus
Last Post 09-16-2008 01:41 PM by Chad Nash. 3 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
Jim EvansUser is Offline
going with the flow
going with the flow
Posts:30
Avatar

--
09-14-2008 05:44 AM

    How can I set the focus to a particular textbox when the form is loaded? I assume that it is done with a client-side event but I cannot get it right.

     

    Any help is very appreciated.

     

    Jim

    Chad NashUser is Offline
    Posts:5260
    Avatar

    --
    09-16-2008 12:13 PM

    Jim,


    Hi. Thanks for your question. I researched this after your post and found a few interesting things (1 bug, 1 work around )



    1. Yes, this is handled using a client side event. This is handled under the 'Initial Javscript Section' and should be formatted as such:



    document.getElementById($(ShortFieldName_FieldID)).focus();



    2. This initial javascript however is also rendered when the form posts back to the page (such as server side validation) so the problem might occur that the form field is set to focused again if you had server side validation. In this case you might use something like this, which would first check to see if the field is empty and then if its empty it would set the focus.



    if ($(ShortFieldName) == '')
    {
    document.getElementById($(ShortFieldName_FieldID)).focus();
    }



    3. The bug I found is that the short field name is not replaced with the actual field ID if the fields 'client side validation' is empty. So you have two work arounds, one is to open up the short field name and save the client side validation with a space in it (it just can't be completely empty ) and the other is to actually get the field ID and use it instead of $(ShortFieldName_Field).



    So... There is a working example of this now at:


    Dynamic Forms Set Field Focus w/ Initial Javascript

     

    Thanks!

     

    -Chad

     

    Chad NashUser is Offline
    Posts:5260
    Avatar

    --
    09-16-2008 12:21 PM
    Also... This brings up a great enhancement request, we will review adding this same feature as a simple checkbox under module configuration that will 'Set focus to first field on form'. Some browsers might do this automatically but I am not sure.

    -Chad
    Chad NashUser is Offline
    Posts:5260
    Avatar

    --
    09-16-2008 01:41 PM
    Update Sent Via Email........



    Chad,

    Followed your instructions to a T, including empty space in client-side validation. I deleted all additional modules from the page. I keep getting an error:

    Line: 24
    Char: 4
    Error: 'FirstName' is undefined
    Code: 0
    URL: etc., etc.

    The code that I am using in the module config is:

    if ($(FirstName) == '')
    {
    document.getElementById($(FirstName_FieldID)).focus();
    }
    I tried using the info from the "View Source" that was id= for the field. I then got a different error:
    Error: Expected ';'

    This is the code from View Source:



    ---
  • film izle
  • 720 izle
  • film
  • sinema izle
  • film makinesi
  • T�rk�e dublaj film
  • film izle
  • film izle
  • baglan film izle
  • sinema izle
  • 1080 film izle
  • film mercegi