Creating And Copy/duplicating A Select/option List Menu With JavaScript September 29, 2022 Post a Comment I have a select list menu: 1 2 Solution 1: I can't test in IE right now, but try using .cloneNode() instead to create the new element. var selectt = document.getElementById("select1").cloneNode(true); selectt.setAttribute("name", "select"+counter); selectt.setAttribute("id", "select"+counter); selectt.onchange = (function( cntr ) { return function() { sellcalculate(cntr); }; })( counter ); cell3.appendChild(selectt); Copy The true argument passed to .cloneNode makes it a deep clone (all descendants). Also, I assumed you want the onchange handler to reference the current value of counter instead of a potentially different future value. As such, I scoped the current value using a new function invocation. Now whatever the value of counter is when this code runs will be the value passed to sellcalculate(). Solution 2: You can use jQuery .clone() like this: $('#select1').clone().attr({'id':'select'+counter, 'name':'select'+counter}).appendTo('cell3Selector'); Copy Test page here. Share Post a Comment for "Creating And Copy/duplicating A Select/option List Menu With JavaScript"
Post a Comment for "Creating And Copy/duplicating A Select/option List Menu With JavaScript"