Click here to Skip to main content
14,666,364 members
Home » Discussions » JavaScript
   

JavaScript

 
GeneralRe: Javascript function error. Pin
and180y10-Jun-20 0:58
Memberand180y10-Jun-20 0:58 
GeneralRe: Javascript function error. Pin
Richard MacCutchan10-Jun-20 1:18
mveRichard MacCutchan10-Jun-20 1:18 
AnswerRe: Javascript function error. Pin
Richard Deeming9-Jun-20 23:13
mveRichard Deeming9-Jun-20 23:13 
GeneralRe: Javascript function error. Pin
and180y9-Jun-20 23:25
Memberand180y9-Jun-20 23:25 
GeneralRe: Javascript function error. Pin
Richard Deeming10-Jun-20 1:26
mveRichard Deeming10-Jun-20 1:26 
GeneralRe: Javascript function error. Pin
and180y10-Jun-20 1:55
Memberand180y10-Jun-20 1:55 
GeneralRe: Javascript function error. Pin
and180y10-Jun-20 23:06
Memberand180y10-Jun-20 23:06 
GeneralRe: Javascript function error. Pin
Richard Deeming10-Jun-20 23:30
mveRichard Deeming10-Jun-20 23:30 
I'm not sure what you mean by "each day"? Do you mean you have multiple sets of inputs for opening time, closing time, and hours?

You can't use the same ID for multiple elements in the same HTML document. You'll need to find a different way of identifying the elements, and linking the three <input> elements for a given day together. For example, you could use the class attribute:
<div class="opening-day">
    <p>Monday</p>
    <p>
        <label>
            Opening:
            <input type='text' class='opening-time' value='00:00'>
        </label>
    </p>
    <p>
        <label>
            Closing:
            <input type='text' class='closing-time' value='00:00'>
        </label>
    </p>
    <p>
        Result:
        <input type='text' class='hours-open' value='00:00' readonly>
    </p>
</div>
var updateHoursOpen = function($div){
    var openingTime = $div.find(".opening-time").val();
    var closingTime = $div.find(".closing-time").val();
    
    var openingMinutes = parseMinutes(openingTime);
    var closingMinutes = parseMinutes(closingTime);
    var minutesOpen = closingMinutes - openingMinutes;
    if (minutesOpen < 0) {
        minutesOpen += 1440;
    }
    
    var hoursOpen = formatMinutes(minutesOpen);
    $div.find(".hours-open").val(hoursOpen);
    return hoursOpen;
};

$(".opening-day").on("keyup", ".openingtime, .closing-time", function(){
    var $div = $(this).closest(".opening-day");
    updateHoursOpen($div);
});
Demo[^]
.find() | jQuery API Documentation[^]
.closest() | jQuery API Documentation[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Javascript function error. Pin
and180y10-Jun-20 23:45
Memberand180y10-Jun-20 23:45 
JokeRe: Javascript function error. Pin
DerekT-P11-Jun-20 2:26
professionalDerekT-P11-Jun-20 2:26 
AnswerRe: Javascript function error. Pin
jkirkerx12-Jun-20 7:57
professionaljkirkerx12-Jun-20 7:57 
GeneralRe: Javascript function error. Pin
and180y12-Jun-20 8:33
Memberand180y12-Jun-20 8:33 
GeneralRe: Javascript function error. Pin
jkirkerx12-Jun-20 8:47
professionaljkirkerx12-Jun-20 8:47 
GeneralRe: Javascript function error. Pin
and180y12-Jun-20 10:48
Memberand180y12-Jun-20 10:48 
GeneralRe: Javascript function error. Pin
jkirkerx12-Jun-20 11:11
professionaljkirkerx12-Jun-20 11:11 
GeneralRe: Javascript function error. Pin
jkirkerx12-Jun-20 10:17
professionaljkirkerx12-Jun-20 10:17 
GeneralRe: Javascript function error. Pin
and180y13-Jun-20 5:57
Memberand180y13-Jun-20 5:57 
GeneralRe: Javascript function error. Pin
Richard MacCutchan13-Jun-20 6:31
mveRichard MacCutchan13-Jun-20 6:31 
GeneralRe: Javascript function error. Pin
and180y13-Jun-20 11:48
Memberand180y13-Jun-20 11:48 
GeneralRe: Javascript function error. Pin
jkirkerx13-Jun-20 7:36
professionaljkirkerx13-Jun-20 7:36 
GeneralRe: Javascript function error. Pin
and180y13-Jun-20 11:47
Memberand180y13-Jun-20 11:47 
QuestionJavaScript slide show works bad on the first page load Pin
Hypnonis8-Jun-20 20:03
MemberHypnonis8-Jun-20 20:03 
AnswerRe: JavaScript slide show works bad on the first page load Pin
Richard Deeming8-Jun-20 22:30
mveRichard Deeming8-Jun-20 22:30 
GeneralRe: JavaScript slide show works bad on the first page load Pin
Hypnonis9-Jun-20 6:33
MemberHypnonis9-Jun-20 6:33 
QuestionJSON object not showing values.. Can someone help Pin
Member 35640766-Jun-20 4:33
MemberMember 35640766-Jun-20 4:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.