Element2.focus () is launched after element1.onblur () does not work in Fx / Chrome / Safari - Salesforce

Am in Salesforce (visualforce) and using custom javascript autocomplete. My requirement is to initiate an automatic full search in the text field element2as soon as a choice is made from offers in another text field element1.

Since I need to scroll through the list of auto offers using the keyboard, I need to focus on a specific field. I am currently doing it element2.focus()right after selecting on element1and starting the search for automatic search on element2.

In addition, in these fields, when the search is performed and the user manually focuses on the field, the automatic offer crashes - this is a sign of the search being canceled. Because of this, I cannot start the search and then callelement2.focus()

Here is what I see in different browsers:

Chrome / Firefox 3.5, 4 / Safari 5.0.3:

  • Select an option from the offers in element1
  • Value in field change
  • Collapse offers
  • The field is blurred, but not sure where the focus is directed. Probably,window

IE 8: 1. Select an option from the suggestions in section element1 2. Importance in field changes 3. Suggestions collapse 4. Blur fields and element2focus 5. Search for fires for this field

, - . (/, ) . javascript- , .

"", , element2.focus() , , 100 , setTimeout(). , , element1 onblur element2.focus(), .

, - ?

:

//mouseclick handler

function handleMouseClick(event){

element1.value = (event.target)?event.target.textContent:event.srcElement.innerText;
callback();

// kills the children and hides the div containing the suggestions
hideAutoComplete();
}


function callback() {
element2.value = '';
element2.focus();
}
+3
1

? - . jQuery, , , , . , , .

<html>
    <head>
        <title>Testing some JS behavior</title>
    </head>
    <body>
        <form id="fooForm">
            <label for="a">A: </label><input id="a"/><br />
            <label for="b">B: </label><input id="b"/><br />
        </form>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
        <script>
            $('#b').focus(function(e) {
                alert("Focusing on b now.");
            });

            $('#a').blur(function(e) {
                alert("Doing my business on element A.");
                $('#b').focus();
                // Stop bubbling, just in case this got triggered by them clicking into B
                return false;
            });
        </script>
    </body>
</html>
+1

All Articles