I have a drop down which has many options. I want that when I select any option then it calls a function through JavaScript.
the code which I used is here
<select name="aa" onchange="report(this.value)"> <--- this is function in .js
<option value="daily">daily</option>
<option value="monthly">monthly</option>
</select>
I want when I select daily then function(daily) is invoked and vice versa.
function report(daily)<-- js function {  
  loadXMLDoc('script/d_report.php','responseTag');
  document.getElementById('responseTag').style.visibility='visible';
  document.getElementById('list_report').style.visibility='hidden';
  document.getElementById('formTag').style.visibility='hidden'; 
} 
function report(monthly) {
  document.getElementById('responseTag').style.visibility='visible';
  loadXMLDoc('script/m_report.php','responseTag');
  document.getElementById('list_report').style.visibility='hidden';
  document.getElementById('formTag').style.visibility='hidden';
}
                A drop-down list (abbreviated drop-down, or DDL; also known as a drop-down menu, drop menu, pull-down list, picklist) is a graphical control element, similar to a list box, that allows the user to choose one value from a list.
JS Dropdown (dropdown. js) A dropdown menu is a toggleable menu that allows the user to choose one value from a predefined list. For a tutorial about Dropdowns, read our Bootstrap Dropdowns Tutorial.
The <select> tab is used with <option> tab to create the simple dropdown list in HTML. After that JavaScript helps to perform operation with this list. Other than this, you can use the container tab <div> to create the dropdown list. Add the dropdown items and links inside it.
<select name="aa" onchange="report(this.value)">    <option value="">Please select</option>   <option value="daily">daily</option>   <option value="monthly">monthly</option> </select>  using
function report(period) {   if (period=="") return; // please select - possibly you want something else here    const report = "script/"+((period == "daily")?"d":"m")+"_report.php";   loadXMLDoc(report,'responseTag');   document.getElementById('responseTag').style.visibility='visible';   document.getElementById('list_report').style.visibility='hidden';   document.getElementById('formTag').style.visibility='hidden';  }   Unobtrusive version:
<select id="aa" name="aa">    <option value="">Please select</option>   <option value="daily">daily</option>   <option value="monthly">monthly</option> </select>  using
window.addEventListener("load",function() {   document.getElementById("aa").addEventListener("change",function() {     const period = this.value;     if (period=="") return; // please select - possibly you want something else here      const report = "script/"+((period == "daily")?"d":"m")+"_report.php";     loadXMLDoc(report,'responseTag');     document.getElementById('responseTag').style.visibility='visible';     document.getElementById('list_report').style.visibility='hidden';     document.getElementById('formTag').style.visibility='hidden';    });  });  jQuery version - same select with ID
$(function() {   $("#aa").on("change",function() {     const period = this.value;     if (period=="") return; // please select - possibly you want something else here      var report = "script/"+((period == "daily")?"d":"m")+"_report.php";     loadXMLDoc(report,'responseTag');     $('#responseTag').show();     $('#list_report').hide();     $('#formTag').hide();    });  }); 
                        Greetings if i get you right you need a JavaScript function that doing it
function report(v) {
//To Do
  switch(v) {
    case "daily":
      //Do something
      break;
    case "monthly":
      //Do somthing
      break;
    }
  }
Regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With