Creating And Copy/duplicating A Select/option List Menu With Javascript January 30, 2024 Post a Comment I have a select list menu: 12Solution 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 ) { returnfunction() { sellcalculate(cntr); }; })( counter ); cell3.appendChild(selectt); CopyThe 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'); CopyTest 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"