SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    focus() is working fine in IE but not in Firefox

    Hi,

    I have validate a text field with onchange event which throw error message, if not satisfied the condition and set the mouse cursor on the same field using document.focus().

    It is working fine in IE, but when used in Firefox, the mouse cursor is moving to the next text field.

    Please let me know the possible solution for the above problem.

    Regards & Thanks,

    Sourav

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Why document.focus() and not element.focus()? (where "element" means the actual text field)

    Surely that is more sensible.

  3. #3
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Thanks for ur suggestion....
    The below function checks the text in the input field for invalid entry.. if error found it focus on the same field... works fine with IE but not with Firefox...

    I have tried ur suggestion.. but it won't works.

    function desig()

    {
    //obj = document.getElementById('designation');
    //obj.value = (obj.value).replace(/^\s+/, '').replace(/\s+$/, '');

    var find=/[0-9\*\=\_\>\<\:\@\&\%\?\$\`\~\#\^\|\+\.\,\;\\\}\{\]\[\\"\!\/\']/;

    if(document.personal.designation.value.search(find)!= -1)
    {
    alert("Only letters are allowed.")
    document.personal.designation.focus();
    //document.personal.designation.select();
    document.personal.designation.select();
    return false;
    }
    else
    return true;
    }

    Please help...

    Regards,

    Sourav

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    In the future, please use code blocks. It makes code easier to read.

    Code:
    document.personal.designation.select();
    What is that? That will cause an error, hence making the entire function fail (and thus focus() fail in Firefox). Remove that line.

    Also, you could make your "find" regular expression a LOT simpler:
    Code:
    var find = /[^a-zA-Z]/

  5. #5
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Thanks for ur reply.

    Focus is still not working in mozilla.

  6. #6
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    OK... did you do what I mentioned in my previous post? And how about answering my question:
    Quote Originally Posted by Raffles
    Code:
    document.personal.designation.select();
    What is that?
    ?


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
  •