user957178
user957178

Reputation: 631

How to set the default selection on the currently added item using jquery

I have this code using this code I am inserting an item from one list box to other list box. I need to set the default selection for tagrget list box item when it is added.

please can any body help me out how to set the deafult selection to the list box.

How to set the default selection to the currently added item to the list box

 function DoInsert(ind) {
            var sourceIndex = $("#lstAvailableCode").val(); /// Selected Item to add
            var targetIndex = $("#lstCodelist").val(); /// added item to the list box(target list box)
            var success = 0;
            var rightSelectedIndex = $("#lstCodelist").get(0).selectedIndex;
            var functionName = "/Ajax/SaveCodeforInsert";
            if (ind == "plan") {
                functionName = "/Ajax/SaveCodeforInsertForPlan";
            }

            $.ajax({
                type: "POST",
                traditional: true,
                url: functionName,
                async: false,
                data: "ControlPlanNum=" + $("#ddControlPlan").val() + "&LevelNum=" + $("#ddlLevel").val() + "&ColumnNum=" + $("#ddlColumn").val() + "&SourcbaObjectID=" + sourceIndex + "&TargetbaObjectID=" + targetIndex + "&userID=<%=Model.userID%>",
                dataType: "json",
                error: function (data) {
                    alert("Error Adding Code");
                    FinishAjaxLoading();
                },
                success: function (data) {
                    if (data == 0) { success = 1; } else { success = data; }
                    FinishAjaxLoading();
                }
            });

Upvotes: 0

Views: 461

Answers (2)

Bitmask
Bitmask

Reputation: 958

could you use

.focus() 

Example:

$("#lstCodelist").focus();

Upvotes: 1

Rafay
Rafay

Reputation: 31043

you can use .focus in the success callback to set the focus

$("element").focus()

Upvotes: 0

Related Questions