Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two drop down list in one i have hours and second one i have minutes
i call function to bind data within this drop down list is "onclick"


but problem is that when by mistake i click on dropdown list twice it add item twice in datalist twice which is not acceptable by me

i want to restrict to add data if i m click on dropdown many time



code for my program


code for drop down

SQL
<select id="hourselect" size="1" onclick="loadhourselector(this);"></select>
                           <select id="minuteselect" size="1" onclick="loadminuteselector(this);"></select>




fuction to add data


C#
function loadhourselector(element)
       {
                           for (var i = 0; i <= 23; i++) {
                   node = document.createElement("Option");
                   textnode = document.createTextNode(i);
                   node.appendChild(textnode);
                   //document.getElementsById("hourselect").appendChild(node);
                   element.appendChild(node);
               }

       }

       function loadminuteselector(element) {
           for (var i = 0; i <= 59; i++) {
               node = document.createElement("Option");
               textnode = document.createTextNode(i);
               node.appendChild(textnode);
               //document.getElementsById("hourselect").appendChild(node);
               element.appendChild(node);
           }
       }
Posted
Comments
ChintanShukla 5-Sep-14 4:20am    
You can clear drop down before binding.

1 solution

Hi..

Juse Use it as :

HTML
<script>
function loadhourselector(element)
       {
                           for (var i = 0; i <= 23; i++) {
                   node = document.createElement("Option");
                   textnode = document.createTextNode(i);
                   node.appendChild(textnode);
                   //document.getElementsById("hourselect").appendChild(node);
                   element.appendChild(node);
               }
 
       }
 
       function loadminuteselector(element) {
           for (var i = 0; i <= 59; i++) {
               node = document.createElement("Option");
               textnode = document.createTextNode(i);
               node.appendChild(textnode);
               //document.getElementsById("hourselect").appendChild(node);
               element.appendChild(node);
           }
       }
</script>
<body onload="loadhourselector(hourselect); loadminuteselector(minuteselect);">
<select id="hourselect" size="1"></select>
<select id="minuteselect" size="1"></select></body>




Enjoy ... :-)
Hemant Singh My Blog[^]
 
Share this answer
 
Comments
Member 10891595 5-Sep-14 7:08am    
this is suitable code for my application in one span but if same fuctionality apply on second span it does not bind data in second span why???/
Hemant Singh Rautela 5-Sep-14 11:17am    
Sorry....! please explain what do you want...!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900