0
function DoInsert(ind) {
            var sourceIndex = $("#lstAvailableCode").val();
            var targetIndex = $("#lstCodelist").val();
            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();
                    var x = $("#lstAvailableCode").val();
                    $("#lstCodelist").val(x);
                    $("#lstCodelist").val(x).css("background-color", "#ffffff");
                }
            });

Here I am trying to adding one item from lstAvailableCode list box to lstCodelist box. after adding into lstCodelist box I am trying to change the textcolor to yellow or some other color. on my success message i wrote something like this. But I am not able to change the color of the text even I am not able to change the backgroud color of that list box. is that something I am doing wrong here?

here is my lstCodelist box code.

  <select id="lstCodelist" size="17" name="lstCodelist" style="width:100%;height:280px;background-color:#EFEFFB;"></select>

 $.fn.fillSelectDD = function (data) {
            return this.clearSelectDD().each(function () {
                if (this.tagName == 'SELECT') {
                    var dropdownList = this;
                    $.each(data, function (index, optionData) {
                        var option = new Option(optionData.Text, optionData.Value);

                         if ($.browser.msie) {
                            dropdownList.add(option);
                        }
                        else {
                            dropdownList.add(option, null);
                        }
                    });
                }
            });
        }

2 Answers 2

2
$("#lstCodelist").val(x).css("background-color", "#ffffff");

should be

$("#lstCodelist").css("background-color", "#ffffff");

.val() returns a value, not the original jQuery object.

To change the font color, you wold use:

$("#lstCodelist").css("color", "#00ffff");
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I need to change the only recently added item to the lstCodelist box.
1
                $("#lstCodelist").val(x).css("background-color", "#ffffff");

should be

                $("#lstCodelist").css("background-color", "#ffffff");

Otherwise you're trying to set a css property on whatever string/number the .val() call returns, and NOT on the actual page element that the value's coming from.

1 Comment

ok thanks how to change the added list item color or text color.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.