SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Halifax
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    final onblur not triggered?

    I was wondering if anyone can help me.

    I've noticed a slight problem with a script I've written, basically I apply an onblur event to fields within a form. As the user tabs or clicks on a field an onblur event for the previous field is triggered.

    However I've noticed if the user clicks on the submit button at the end of the form, instead of tabbing to the submit button the onblur event is never called.

    Has anyone come across this before?

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    London, UK
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A common problem. Use an onsubmit event trigger on the form to trigger all the onblurs manually. Perhaps something like this:
    PHP Code:
    function submitform(f) {
      var 
    inputs f.getElementsByTagName('INPUT');
      for (var 
    i=0i<inputs.lengthi++)
        if (
    inputs[i].getAttribute('onblur')) {
          
    inputs[i].getAttribute('onblur')();
        }

    HTML Code:
    <form action="#" onsubmit="submitform()">
    <input name="something" onblur="foo()" />
    <input type="submit" />
    </form>

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Halifax
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd guess as much.

    Thanks for taking the time to reply!

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Halifax
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've had another look at this but I'm not entirely sure this is going to work.

    I'm assigning the onblur event unobstrusively, therefore when you return the inputs there will not be an onblur attribute.

    Does anyone have an idea how you can manually trigger an event trigger such as onblur, onsubmit etc


Bookmarks

Posting Permissions

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