Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2004
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setting focus to current form element

    I am trying to set the focus to the current element in a javascript. I can't specify the field name because the script is used site wide. It is placed in an a href tag, but I am open to suggestions!

    Thanks!!!

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    I'm not entirely sure what you mean.
    What do you mean by the 'current' element?

    Do you have a url where we can see what you're referring to?

  • #3
    New Coder
    Join Date
    Oct 2004
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Bill Posters
    I'm not entirely sure what you mean.
    What do you mean by the 'current' element?

    Do you have a url where we can see what you're referring to?
    The url is www.safetypilots.com/dev/admin/schedule.php (login=school1/iceman). To the left there is a javascript popup calendar with date field. What I am tring to do is set the date using the script (works as expected), but I need the form to be submitted when a new date is selected. I tried onChange="this.form.submit" in the date field, but that doesn't work. OnFocus does work, but I need to somehow implement a set focus to the date field when the script enters the date.

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    this.form.submit()

    would be what is required to submit the form.

  • #5
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    You should probably stick with onchange, so that if the user manually enters it it submits.

    Then, you need to fire the onchange event if you set the value using javascript:

    Code:
    // *** Credit to PPK at www.quirksmode.org for the education on this ***
    function dispatchEvent(p_element, p_event)
    {
        if (p_element.fireEvent)    // *** IE event dispatching ***
            p_element.fireEvent("on" + p_event);
        else    // *** !!!NOTE!!! NOT DEFENSIVE ***
        {   // *** DOM event dispatching ***
            var evt = document.createEvent("HTMLEvents");
            evt.initEvent(p_event, true, true);
            p_element.dispatchEvent(evt);
        }
    }   // *** End Function: dispatchEvent(p_element, p_event) ***
    
    dispatchEvent(document.getElementById('yourDateField'), 'change');


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •