Appending The Items Into The Combo Box August 29, 2023 Post a Comment I need to add the item in a combo box for a particular number of times.This is my code. for(i=0;i<3;i++) { othercompaniesli.innerHTML= 'Solution 1: var tmpStr = '<selectonchange="document.location.href = this.options[this.selectedIndex].value;">'; for(i=0;i<3;i++) { tmpStr+= '<optionVALUE="http://www.google.com">'+fStr1[0]+'</option> '; } tmpStr = '</select>'; othercompaniesli.innerHTML = tmpStr; CopySolution 2: try othercompaniesli.innerHTML +=.Solution 3: Since you are using equal to =, it is re-assigning to the same elementUse append()$('#othercompaniesli').append('<selectonchange="document.location.href = this.options[this.selectedIndex].value;"><optionVALUE="http://www.google.com">'+fStr1[0]+'</option></select>'); CopyNote that your select and option elements are repeating, you need to change it accordingly.Solution 4: Place select tag out of loop var selectTag = '<selectonchange="document.location.href = this.options[this.selectedIndex].value;">'; for(i=0;i<3;i++) { selectTag += '<optionVALUE="http://www.google.com">'+fStr1[0]+'</option>'; } selectTag +="</select>" othercompaniesli.innerHTML = selectTag; CopySolution 5: What you are doing is the inside the loop you are ending your select tag , so every element will have it own select opening and closing tag. and you are just updating your innerHTML with the newer element thats why its getting the last element. var openingTag= '<selectonchange="document.location.href = this.options[this.selectedIndex].value;">'; for(i=0;i<3;i++) { openingTag+= '<optionVALUE="http://www.google.com">'+fStr1[0]+'</option> '; } openingTag= '</select>'; othercompaniesli.innerHTML = openingTag; Copy Share Post a Comment for "Appending The Items Into The Combo Box"
Post a Comment for "Appending The Items Into The Combo Box"