Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How do I change an HTML selected option using JavaScript?

<a href="javascript:void(0);" onclick="selectItemByValue(document.getElementById('personlist'),11)">change</a>

function selectItemByValue(elmnt, value){

  for(var i=0; i < elmnt.options.length; i++)
  {
    if(elmnt.options[i].value === value) {
      elmnt.selectedIndex = i;
      break;
    }
  }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #How #I #change #HTML #selected #option
ADD COMMENT
Topic
Name
2+7 =