Home Ask Login Register

Developers Planet

Your answer is one click away!

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";

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.


abhay vyas February 2016

hope this will help you..

<!DOCTYPE html>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">
        $('select#sel').find('option').each(function() {
            var t=$(this).val();
    <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>
    <div id="mySelect"></div>

Post Status

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


Leave an answer

Quote of the day: live life