简体   繁体   中英

Dialog box not loading the correct values— JavaScript/Jquery

I have a div under that I have few elements like radio buttons, list boxes etc. When user clicks on a button we are putting that div in a dialog box and showing it as pop up. Here the issue is, when we set any data to the elements (like changing the value, or selecting check boxes ) It is not reflecting in the popup.

HTML CODE

<!--dialog -->
<div id="edit">
            <div id="dialog_contents">
            </div>
</div>

<div id="abc123">
lisbox...name="editListBox" id="editListBox"
checkbox..name="editCheckBox"  id="editCheckBox"
</div>

JS CODE

function edit()
{
        $("#editListBox" ).val('3');
        $("#editCheckBox").attr( 'checked', true );
        var data =  $("#abc123" ).html();
        $('#dialog_contents').html(data);
        $(edit).removeClass('hide').dialog('open');
}


    $('#edit').dialog({
            modal: true,
            draggable: true,
            resizable: false,
            autoOpen: false,
            width: 650,
            height: 750,
            cache: false,
            position:'center',
            open: function(event, ui) {

                window.setTimeout(function()
                        { jQuery(document) .unbind('mousedown.dialog-overlay') .unbind('mouseup.dialog-overlay') ; }, 100);
            },
            buttons: {
                "Cancel": function() {

                },
                "Edit": function() {
                    $( this ).dialog( "close" );

                }
            }               
        }); 

Only problem is , whatever the values i'm setting in the js function are not reflecting in the pop up. When i print them or display it in the main screen it is showing them correctly.

PS Attached sample code, ignore the syntax.

Thanks

I found the issue. In my case , when i add the existing div to another div. I'm having duplicate names,So when i tried to set values to those fields using name or id, its not giving me the element(may be because of ambiguity).

When i changed from id to class, the problem got resolved, i can find any element now and change its value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM