[Solved] If function in drop down list using JavaScript [closed]


function myFunction()
{
    var internetElem =  document.getElementById("internet");
    var internet = internetElem.options[internetElem.selectedIndex].value;
    var computerElem =  document.getElementById("computer");
    var computer= internetElem.options[internetElem.selectedIndex].value;

   if (internet=="no"||computer=="yes") {
      x="check your cable is not cut or loose";
   } else if (internet=="no"||computer=="yes") {
      x="connection problem";
   } else {
      x="other problems....";
   }
   document.getElementById("Solution").innerHTML=x;
}

You need something like above. Just find an element by its id, take index of selected element and get a value of selected option. Note that value will return what you have placed in <option value="..." and string comparison is case sensitive, so internet == "no", will not work and you should change it to internet == "No" (or change a value in HTML markup)

1

solved If function in drop down list using JavaScript [closed]