Tuesday, March 28, 2017

Javascript to get drop down selected value

Java script to get drop down selected value.

 <!DOCTYPE html>  
 <html>  
 <head>  
 <style>  
 #myDIV {  
   width: 100%;  
   padding: 50px 0;  
   text-align: center;  
   background-color: lightblue;  
   margin-top:20px;  
 }  
 </style>  
 </head>  
 <body>  
 <p>Java script to get dropdown selected value :</p>  
 <select onchange="myFunction()" id="priority">  
 <option></option>  
 <option>1</option>  
 <option>2</option>  
 <option>3</option>  
 </select>  
 <p id="prioritydefination"></p>  
 <p><b>Note:</b> The element will not take up any space when the display property set to "none".</p>  
 <script>  
 function myFunction() {  
   var priority = document.getElementById("priority").value;  
   if(priority === ''){  
        document.getElementById("prioritydefination").innerHTML = "You selected: " + priority ;  
   }else if(priority == 1){  
         document.getElementById("prioritydefination").innerHTML = "You selected: " + priority ;  
       }else if(priority == 2){  
             document.getElementById("prioritydefination").innerHTML = "You selected: " + priority ;  
        }else if(priority == 3){  
        document.getElementById("prioritydefination").innerHTML = "You selected: " + priority ;  
   }  
 }  
 </script>  
 </body>  
 </html>  
 
Output:
 

No comments:

Post a Comment