1

I have two listbox, A & B:

enter image description here

when I double click on an item of A , the item will be added in List B. And i have done this. List B visually show the value, but when I go to the view source of the page, I dont see new <option>.

This is my List A options.

enter image description here

This is my List B options (before and after addition and it remains same whatever items added. this is my problem.):

enter image description here

It should have one <option>. like

<option value="VSNR">VSNR</option>

what is my code is :

   $('#lstXLSCol').on('dblclick', function () {
        var item = $('#lstXLSCol').find(":selected").text();

        var newOption = { item: item };
        $('option:selected', this).remove();
        $.each(newOption, function (val, text) {
            if (text != "")
                $('#lstXLSSelectedCol').append(new Option(text, val));
        });
    });

EDIT 1 :

I have found it pressing F12 in IE. but the values are like below:

enter image description here

but, i wanted to insert the value same as text. What should be changed in my jquery code?

2

4 Answers 4

1

you can not see them. The source is just used to build the initial DOM that represents the document. Dynamically created elements are only inserted in the DOM.

But you can analyse such elements with a DOM viewer like Safari’s WebInspector or the Firefox extionsion Firebug. Firefox can also show source code that represents such dynamically created elements by selecting that element an choosing View Selection Source in the context menu.

See this

Sign up to request clarification or add additional context in comments.

Comments

1

take out the space between params and :last

$('#lstXLSSelectedCol:last').html('<option value=\''+item+'\'>'+item+'</option><option>');

Comments

0
$('#lstXLSSelectedCol:last').live('change', function () {

            var option_selected = $('option:selected', this).val();

                $('#lstXLSSelectedCol:last').append($('<option>', {
                    value: option_selected
                }).text(option_selected));        


        });

Comments

0

You won't see dynamically added elements in the source of your page.

Use your browser's console to inspect the DOM.

Normally it's enough to right click on the element and select "inspect" from the context menu, otherwise see this link for how to access your browser's console.

1 Comment

Your entire code looks a bit weird to me. If you make a fiddle, that'll make life much easier.

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.