Home » Javascript » javascript displaying dropdown list title

javascript displaying dropdown list title

Posted by: admin August 19, 2018 Leave a comment


I have a dropdown list that is by javascript and it is working fine.
The question is how do i display out the title (YES/NO) of the dropdown.

 function createSelect2(tag) {
 var select = document.createElement("select");
 select.id = "select-" + rowNumber;
 var array = [{
  title: "YES!",
  value: "return 0;"
  title: "NO",
  value: "return 1231 * area;"

i tried using the below method in another function but it just could not work

var h = document.getElementById("tag");
var yesno = h.options[h.selectedIndex].text;

Please advice thannkss