We help IT Professionals succeed at work.

Jquery focus() function is not working

hariaspind
hariaspind asked
on
i have a fuction which show a popup with textarea values from parent webpage textbox.

When i close the popup the data is being transfered to the textarea in parent webpage ,but the focus is not going back to the parent page texarea.

Any help?


function ShowAll(divToPopupID, titleID) {

        $("#divResult").find("textarea").text($(divToPopupID).html());
        $("#divResult").addClass("ShowPanel");
        $("#divResult").dialog({
            width: 800,
            autoOpen: false,
            modal: true,
            title: $(titleID).text(),
            closeOnEscape: false,
            buttons:
            {
                "Cancel": function() {
                    $(this).dialog("close");
                },
                "Close": function() {
                    $(divToPopupID).html($("#divResult").find("textarea").text());
                       $(divToPopupID).Focus();
                    $(this).dialog("close");
                   $("#divResult").removeClass("HiddenPanel");
                }
            }
        });
        $("#divResult").dialog("open");        
    }
Comment
Watch Question

add quotes

try this:

  $('divToPopupID').Focus();
if  divToPopupID is DIV's id

then try this:

 $('#divToPopupID').Focus();
leakim971Multitechnician
Distinguished Expert 2019

Commented:
Use : $( "#" + divToPopupID ).focus();

Author

Commented:
Both are not working .

Author

Commented:
In code behind while calling the ShowAll methnod i am passing the "#" as below .

this.hlProjectPurpose.Attributes.Add("onclick", "ShowAll('#" + txtProjectPurpose.ClientID + "','#" + lblProjectPurpose.ClientID + "');");
leakim971Multitechnician
Distinguished Expert 2019

Commented:
ok so what about the case ?  focus() and not Focus()

http://api.jquery.com/focus/

Author

Commented:
Focus is not working .
leakim971Multitechnician
Distinguished Expert 2019

Commented:
>Focus is not working .

I know, it's focus

Author

Commented:
do u mean focus() will work?.I tried earlier it is not working.

Multitechnician
Distinguished Expert 2019
Commented:
focus is the right one : http://api.jquery.com/focus/

it's time to give us a live link or a simple version of your page
do one thing,

just right click on page and see page source code and search for same 'divToPopupID' control.
Copy its ID value and use:

$('#IDvalue').Focus();

change IDvalue to copied value.

Author

Commented:
The below html is in usercontrol

<table class="tabTable">
<tr>
        <td>
          <asp:Label ID="lblEoAgencyCollaborations" runat="server" Text="Explanation of Agency Collaborations:"></asp:Label>
          <asp:HyperLink ID="hlEoAgencyCollaborations" CssClass="AnchorDefault" runat="server" Text="Show All"></asp:HyperLink>
        </td>
    </tr>

<tr>
        <td ><asp:TextBox ID="txtAgencyCollaborations" runat="server" SkinID="LargeTBox"
        TextMode="MultiLine" onchange="setProjectTabDirty();"></asp:TextBox></td>
    </tr>
</table>


User control Page_load ()
{
 //Show All
        this.hlEoAgencyCollaborations.Attributes.Add("onclick", "ShowAll('#" + txtAgencyCollaborations.ClientID + "','#" + lblEoAgencyCollaborations.ClientID + "');");

}

The page which loads the usercontrol  has the below jquerys method.

function ShowAll(divToPopupID, titleID) {

    if ($(divToPopupID).attr('ReadOnly') == true) {
        $("#divResult").find("textarea").attr("readonly", "readonly");
        button = $("#divResult").find("button:contains('Close')");
        alert(button);
        button.unbind();
        button.addClass('ui-state-disabled');

    }
 
        $("#divResult").find("textarea").text($(divToPopupID).html());
        $("#divResult").addClass("ShowPanel");        
        $("#divResult").dialog({
            width: 800,
            autoOpen: false,
            modal: true,
            title: $(titleID).text(),
            closeOnEscape: false,
            buttons:
            {
                "Cancel": function() {
                    $(this).dialog("close");
                },
                "Close": function() {
                    $(divToPopupID).html($("#divResult").find("textarea").text());
                    setTabDirty();//This is for invoking the save message ,if the user moves to another tab without saving data in current tab.
                    $(this).dialog("close");
                    $("#divResult").removeClass("HiddenPanel");
                }
            }
        });
        $("#divResult").dialog("open");        
    }

So when i edit the textarea in jquery dialog and close it ,the onchange even of the real text box should be fired.That's my issue.