locked
how to creates an event that fires any time any "input" type element gets focus RRS feed

  • Question

  • User229488726 posted

    how creates an event that fires any time any "input" type element gets focus

    this is my script . it work fine in normal text box and  button  but when a text box which mode set to MultiLine this function not working 

    can any one help me how to solve this problem  

    <script>

    $("input").focus(function (e) {
    if ($(e.target).attr('type') != 'submit') {
    var activeElem = document.activeElement.name;
    $("#hdnSelectedField").val(activeElem);
    $("#selectedElementName").html(activeElem);
    }
    });

    </script>

    Wednesday, August 17, 2016 10:35 AM

Answers

  • User475983607 posted

    This function work in page load but i need 

    The page must be fully loaded before adding the focus event handler. Otherwise the page cannot see the input elements.  If your JavaScript is in the head then you'll need to place the focus event script within the page ready event or you can place the code at the bottom of the HTML file below the input elements.

    <script type="text/javascript">
    
        $(function(){
            $('input').focus(function () {
                console.log($(this).attr('id'));
            });
        });
    
    </script>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 17, 2016 1:00 PM
  • User-474980206 posted

    $("input,textarea").focus(function (e) {

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 17, 2016 3:16 PM

All replies

  • Wednesday, August 17, 2016 11:02 AM
  • User229488726 posted

    This function work in page load but i need 

    any time any "input" type element gets focus

    Wednesday, August 17, 2016 11:17 AM
  • User475983607 posted

    This function work in page load but i need 

    The page must be fully loaded before adding the focus event handler. Otherwise the page cannot see the input elements.  If your JavaScript is in the head then you'll need to place the focus event script within the page ready event or you can place the code at the bottom of the HTML file below the input elements.

    <script type="text/javascript">
    
        $(function(){
            $('input').focus(function () {
                console.log($(this).attr('id'));
            });
        });
    
    </script>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 17, 2016 1:00 PM
  • User-474980206 posted

    $("input,textarea").focus(function (e) {

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 17, 2016 3:16 PM