This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I want to create hours calculator

 
rushikesh kalikar
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33670
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or step through the code with the browser's debugger.
 
rushikesh kalikar
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33670
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic