aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes I want to create hours calculator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "I want to create hours calculator" Watch "I want to create hours calculator" New topic
Author

I want to create hours calculator

rushikesh kalikar
Greenhorn

Joined: Jul 13, 2011
Posts: 7
we are designing timesheet management system.in that we have to calculate hours given by user ..
we done something but its not working properly...i will not calculate hours when starthours and endhours are same.
please help me

function calculatehours(){

var startworkhours = document.getElementById("firsthourstart").value;
var startworkminutes = document.getElementById("firstminutestart").value;
var endworkhours = document.getElementById("firsthourend").value;
var endworkminutes = document.getElementById("firstminuteend").value;

if(endworkhours>=startworkhours){

if(startworkhours!="Select" && startworkminutes!="Select" && endworkhours!="Select" && endworkminutes!="Select"){


var totHours1 = 60*(startworkhours)+(1*startworkminutes);
var totHours2 = 60*(endworkhours)+(1*endworkminutes);


var linearminutesworked = (totHours2-totHours1);

var hoursWorked = parseInt(linearminutesworked/60);
var minutesWorked = linearminutesworked-(hoursWorked*60);

if (minutesWorked < 10){
minutesWorked = "0"+minutesWorked;
}

document.getElementById("totalTime").value = hoursWorked+":"+minutesWorked;
}
}else(startworkhours>endworkhours){
alert('Invalid Information');document.timeWorked.value='';return false}
}
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31079
    
163

Welcome to CodeRanch!

Which is the first line where the variable isn't what you expect it to be? (You can add an alert() to print out the values to find this out.)


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Or step through the code with the browser's debugger.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
rushikesh kalikar
Greenhorn

Joined: Jul 13, 2011
Posts: 7
I want to calculate time upto 'n' but by using 'getElementById' we have to create new one for each ....
Please tell me if there is any other way ...
In this case can i use 'getElementByName' ?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31079
    
163

What do you mean by "up to n"? I don't see an "n" in your example.

Using byName might not help you. How will you know which text fields go with each other? Can you explain more about what you are trying to do?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I want to create hours calculator