qusqui21 February 2016

Set dropdown list from server value on dynamic created div

I have a problem with setting value of dropdown list in dynamic created div with edit form.

document.getElementById("edit-entry").innerHTML = "";
var div = document.createElement('div');
div.className = 'edit';
div.innerHTML =  "form html";
document.getElementById('edit-entry').appendChild(div);

in html it is

<div id="edit-entry"></div>

on console it's working ("#sel-change-app").val("9"); But when i try to get it under appendChild, or with $(function() { } still no change. How to check if div is ready for setting values? As i debug i see that sel-change-app is slower than div, couse list is from server.

Answers


abhay vyas February 2016

hope this will help you..

<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $('select#sel').find('option').each(function() {
            var t=$(this).val();
            $("#mySelect").append(t+"<br>");
        });
    }); 
    </script>
</head>
<body>
    <select id="sel" name="sel">
        <option value="o1">1</option>
        <option value="o2">1</option>
        <option value="o3">1</option>
        <option value="o4">1</option>
    </select>
    <div id="mySelect"></div>
</body>
</html>

Post Status

Asked in February 2016
Viewed 2,792 times
Voted 13
Answered 1 times

Search




Leave an answer