SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Removing focus from a text field

    I need to make an element lose focus when I submit a form.

    document.getElementById('element_name').blur(); works perfectly.

    The thing I need is to know how to submit all elements on the page so that I don't have to manually enter every text box in the JS code.

    Can you make all forms on the page lose focus?

    I'm doing this because on touch screen devices, if you have the virtual keyboard open and submit via Ajax it doesn't close the keyboard so I want to lose focus on all elements whenever I submit via Ajax.

    As mentioned, document.getElementById('element_name').blur() works perfectly if you manually enter each element name (and they virtual keyboard closes), I just want to know if there is an easy way to lose focus on all fields, and I can then tack it onto the end of my Ajax function and never have to think about it again (rather than making it a part of every page I create).

    Thanks.

  2. #2
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,805
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Have you tried:

    HTML Code:
      input:focus {background-color:#ff9;color:#00f}

  3. #3
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think that has anything to do with it (unless I am completely mistaken).

    I think your code will change the colour of the text box when it is clicked on.

  4. #4
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Do you want to lose focus on all fields onsbumit of the form button? if yes I think the following code would help you.

    Code JavaScript:
     
    $('#button').submit(function() {
     
    $('input').blur();
     
    });

    Thanks,
    Raghavender Reddy


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
  •