Results 1 to 4 of 4

Thread: HTML/JavaScript onfocus and onblur not firing

  1. #1
    Join Date
    Oct 2012
    Location
    Geekland
    Beans
    Hidden!
    Distro
    Kubuntu

    HTML/JavaScript onfocus and onblur not firing

    I am trying to get the textboxes to clear on focus and if they are empty on unfocus they revert to the default values. However neither onfocus nor onblur is firing. I have a jsfiddle with the code here. Any help is appreciated.
    Last edited by wolfgentleman; April 29th, 2013 at 06:26 PM.

    Sincerely,
    Patrick Thomas (Timberwolf)
    Timberwolf Programmers Owner & Founder


  2. #2
    Join Date
    Oct 2012
    Location
    Geekland
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: HTML/JavaScript onfocus and onblur not firing

    bump

    Sincerely,
    Patrick Thomas (Timberwolf)
    Timberwolf Programmers Owner & Founder


  3. #3
    Join Date
    Jun 2009
    Location
    Land of Paranoia and Guns
    Beans
    194
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: HTML/JavaScript onfocus and onblur not firing

    Your focus event is not firing. However, your unfocus is. I'm not quite sure of the reason why, but you could probably save yourself some trouble by using the placeholder attribute. http://html5doctor.com/html5-forms-i...s/#placeholder
    Also, consider using the addEventListener way of doing this, as the attributes are discouraged:
    Code:
    document.getElementById('ip1').addEventListener("focus", function () {
        ...
    }, false);
    Don't use W3Schools as a resource! (Inconsequential foul language at the jump)
    Open Linux Forums (More foul language, but well worth it for the quality of support and good humor.)
    If you want to discuss W3Schools, please PM me instead of posting.

  4. #4
    Join Date
    Oct 2012
    Location
    Geekland
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: HTML/JavaScript onfocus and onblur not firing

    I could not get the onblur event to fire, I don't know what you are doing different... I tried the .addEventListener first, it didn't work. Then I used the placeholder attribute and it did work nicer than what I was trying to do. So thank you for your help.

    BTW: if it makes any difference I am using Firefox, I don't know why that would be preventing the onblur to fire but whatever...

    Sincerely,
    Patrick Thomas (Timberwolf)
    Timberwolf Programmers Owner & Founder


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
  •