onload then check if “.stime[val!=‘’]” then run function recalcPrices() with setInterval, which is okay.
My question is, how to run the recalcPrices() with setInterval when I clicked “.btnStart” ??
function recalcPrices()
{
$.each($(".stime[value!='']"), function(k, v) {
let tid = $(v).data("tid")
let bid = $(".bid[data-tid="+tid+"]").val()
let start = $(".sdate[data-tid="+tid+"]").val() + ' ' + $(".stime[data-tid="+tid+"]").val()
let end = "";
if ($(".etime[data-tid="+tid+"]").val() != '') {
$end = $(".edate[data-tid="+tid+"]").val() + ' ' + $(".etime[data-tid="+tid+"]").val()
}
$.get(
"",
{"ajax":"getPrice", "start":start, "end":end, "bid":bid},
function(resp) {
$(".cold[data-tid="+tid+"]").html(resp)
console.log('%c'+tid,'background: #ffc0c0; padding:5px; border-radius: 60%;', start, end, resp)
},
"TEXT"
)
})
}
$().ready( function() {
$(".stime[val!='']").each( function(k,v) {
recalcPrices()
myInterval = setInterval('recalcPrices()', 1000)
})
$(".sdate").on("change", function() {
let tid = $(this).data("tid")
let bid = $(this).data("bid")
console.log(tid + "." + bid + "Change event" + this.value);
})
$(".btnStart").click( function() {
var tid = $(this).data("tid")
$.get(
"",
{"ajax":"startBooking", "tid":tid},
function(resp) {
$(".sdate[data-tid="+tid+"]").val(resp.sdate).show()
$(".stime[data-tid="+tid+"]").val(resp.start).show()
$(".bid[data-tid="+tid+"]").val(resp.bid)
},
"JSON"
)
$(this).hide()
$(".btnFinish[data-tid="+tid+"]").show()
$(".cold[data-tid="+tid+"]").html('$0.00')
$(".tblimg[data-tid="+tid+"]").removeClass("w3-grayscale-max w3-opacity")
console.log("started")
//recalcPrices()
//myInterval = setInterval('recalcPrices()', 1000)
})