Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

create a drop down to select time javascript

function populate(selector) {
    var select = $(selector);
    var hours, minutes, ampm;
    for(var i = 420; i <= 1320; i += 15){
        hours = Math.floor(i / 60);
        minutes = i % 60;
        if (minutes < 10){
            minutes = '0' + minutes; // adding leading zero
        }
        ampm = hours % 24 < 12 ? 'AM' : 'PM';
        hours = hours % 12;
        if (hours === 0){
            hours = 12;
        }
        select.append($('<option></option>')
            .attr('value', i)
            .text(hours + ':' + minutes + ' ' + ampm)); 
    }
}

populate('#timeSelect'); // use selector for your select
Comment

PREVIOUS NEXT
Code Example
Javascript :: JQuery UI Saving Sortable List 
Javascript :: discord.js find word inside comment 
Javascript :: custom ngModel 
Javascript :: comparare due array di numeri javascript 
Javascript :: calculate sum in empty array javascript 
Javascript :: test cases in react 
Javascript :: react popup 
Javascript :: find element in array underscore js 
Javascript :: export socket io connection in react 
Javascript :: set cookie in javascript 
Javascript :: remote with post data jquery ajax example 
Javascript :: hardhat async test 
Javascript :: json returning object object 
Javascript :: cant see serviceWorker.js 
Javascript :: rendering an array inside an array in react 
Javascript :: how to get max value from array of objects in javascript 
Javascript :: deleting an instance in sequelize 
Javascript :: jquery onchage html content 
Javascript :: javascript concatenation 
Javascript :: how to loop through all tags in html 
Javascript :: onselect in zebra datepicker 
Javascript :: JavaScript switch With Multiple Case 
Javascript :: slice javascript 
Javascript :: Fake Binary 
Javascript :: movement of objects in javascript 
Javascript :: service worker self.clients 
Javascript :: react hooks link to external site 
Javascript :: array length 
Javascript :: change node bash root 
Javascript :: react native full screen view video player 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =