Featured post
javascript - help me wrap up a slider into a function I can call -
a while ago posted question jquery slider here
this works treat need wrap in function each day of week can pass in values of values hard coded. i've tried doing , firebugs telling me slider undefined.
all want call function 7 times each day of week , pass in id slider, id div holds times, id div holds generated table, id table , id button.
the current code this:
var starttime; var endtime; $("#slider-range").slider({ range: true, min: 0, max: 1439, values: [540, 1020], step:5, slide: slidetime, /*change: */}); function slidetime(event, ui){ var minutes0 = parseint($("#slider-range").slider("values", 0) % 60); var hours0 = parseint($("#slider-range").slider("values", 0) / 60 % 24); var minutes1 = parseint($("#slider-range").slider("values", 1) % 60); var hours1 = parseint($("#slider-range").slider("values", 1) / 60 % 24); starttime = gettime(hours0, minutes0); endtime = gettime(hours1, minutes1); $("#time").html('<p>opening time: ' + starttime + '</p><p>closing time: ' + endtime + '</p>'); function gettime(hours, minutes) { minutes = minutes + ""; if (hours == 12) { hours = 12; } if (hours > 12) { hours = hours; } if (minutes.length == 1) { minutes = "0" + minutes; } return hours + ":" + minutes ; function gettimeloop(minutesloop) { minutesloop = minutesloop + ""; if (minutesloop.length == 1) { minutesloop = "0" + minutesloop; } returnminuetsloop; } } slidetime(); $('#btnupdatetable').click(function(){ var startloop = parseint($("#slider-range").slider("values", 0)); var endloop = parseint($("#slider-range").slider("values", 1)); $('#bookingtimestable').remove(); $('<table id="bookingtimestable">').appendto('#generatedresulttable'); for(i = startloop; < endloop; i+=5) { $('<tr><td style="width:145px; padding-left: 10px;">' + parseint(i/ 60 % 24) + ':' + gettimeloop(parseint(i % 60)) + '</td><td style="padding-left: 10px;" ><input class="chx" name="' + parseint(i/ 60 % 24) + ':' + gettimeloop(parseint(i % 60)) + '" type="checkbox" value="' + parseint(i/ 60 % 24) + ':' + gettimeloop(parseint(i % 60)) + '" /></td></tr>').appendto('#bookingtimestable'); } var i=0; var period = $('#cbobooking').val(); $('.chx').each(function(){ $(this).attr('checked',(i % period ==0)); i++; }); $('#bookingtimestable tr:odd').css('background','#dedede'); });
if me on great! being implemented 7 days of week on tabbed interface , want , running fast
dan
just quick note of assistance... wrap entire thing in constructor function, form closure upon of contained variables , functions. pass in redefine function arguments:
function bookingslider (sliderid, timesdivid, tabledivid, tableid, buttonid) { // code }
use constructor instantiate new instances of bookingslider, passing in appropriate values:
var bsmonday = new bookingslider('slider-range', 'time', 'generatedresulttable', 'bookingtimestable', 'btnupdatetable');
make sure substitute string constants appropriate arguments in function:
'#btnupdatetable'
becomes
'#' + buttonid
- Get link
- X
- Other Apps
Comments
Post a Comment