Can someone please tell me what the the Javascript equivilant of this VB Code is
VB Code:
i = 1.33 i=int(i)
I want to lose the decimal places.
Thanks
Printable View
Can someone please tell me what the the Javascript equivilant of this VB Code is
VB Code:
i = 1.33 i=int(i)
I want to lose the decimal places.
Thanks
var i = 1.33
i = parseInt(i)
This will return an integer type but it won't round up -> 1.9 will return 1.
var i = 1.33
i = Math.round(i)
Rounds the number but I'm not 100% sure if it returns an integer type - might need to parseInt afterwards.
Thanks.
But i am also getting this error:
TypeError: getField("In") has no properties
3:Document-Level:TotalTime
this is what i am sending
[JavaScript]
event.value=totalTime("Text2","Text3","Text5");
[/JavaScript]
where Text2 = 12:00
Text3=17:00
Text5= 01:15
[JavaScript]
function totalTime(In,Out,Lunch)
{
var start=getField("In").value;
var finish=getField("Out").value;
var lunch=getField("Lunch").value;
var sa=start.split(":");
var fa=finish.split(":");
var la=lunch.split(":");
var startminutes=(sa[0]*60)+(sa[1]*1);
var finishminutesa=(fa[0]*60)+(fa[1]*1);
var lunchminutes=(la[0]*60)+(la[1]*1);
if (finishminutesa <= startminutes) {
var finishminutes=finishminutesa+720
}
else if ((finishminutesa-startminutes-lunchminutes)/60<=0){
var finishminutes=finishminutesa+720
}
else {
var finishminutes=finishminutesa
};
var totalHours=parseint(finishminutes-startminutes-lunchminutes)/60;
if(isNaN(totalTime))totalTime=0;
var totalMin=((finishminutes-startminutes-lunchminutes)/60)-TotalHrs;
var displaytotal=totalHours +":"+(totalMin*60)
return displaytotal;
}
[/JavaScript]
I just dont get it....
Ok so you're passing 3 variables into the function totalTime and then trying to access these values using:
Try usingCode:var start=getField("In").value;
var finish=getField("Out").value;
var lunch=getField("Lunch").value;
var start = In
var finish = Out
var lunch = Lunch
Might be better to rename two of these variables from IN and OUT not sure if they are reserved words.
You are the "Man"... Thanks
But one more quick question what would
cStr()
Left("String",2)
Right("String",2)
Mid(("String",1,3)
be in javascript, or if you know a site that would have all this stuff.
Thanks
--- dont worry about this part i found the problem-----
I am just getting NaN:NaN returned any ideas
[Java Script]
function TotalTime(StartTime,FinishTime,Lunch)
{
var start=StartTime;
var finish=FinishTime;
var lunch=Lunch;
var sa=start.split(":");
var fa=finish.split(":");
var la=lunch.split(":");
var startminutes=(sa[0]*60)+(sa[1]*1);
var finishminutesa=(fa[0]*60)+(fa[1]*1);
var lunchminutes=(la[0]*60)+(la[1]*1);
if (finishminutesa <= startminutes) {
var finishminutes=finishminutesa+720
}
else if ((finishminutesa-startminutes-lunchminutes)/60<=0){
var finishminutes=finishminutesa+720
}
else {
var finishminutes=finishminutesa
};
var totalHours=parseInt(finishminutes-startminutes-lunchminutes)/60;
if(isNaN(totalTime))totalTime=0;
var totalMin=((finishminutes*1-startminutes*1-lunchminutes*1)/60)-totalHours;
var displaytotal=totalHours + " " + finishminutes + " " + startminutes + " " + lunchminutes
return displaytotal;
}
[/Java Script]
A good site for refrence is http://www.devguru.com.
What are the values being passed into the function? If you are getting NaN (not a number) returned then you might be having problems with datatypes. Left, Right and Mid can only be used on strings.
I managed to solve the NaN problem, thanks do you know what the equivilant of Len() is??
Len(variablename)
would be
variablename.length
Thanks
but how would you pad out a string/Number?? without having to finding out the length of the string
string = Right("00" & string,2)
the only thing I can fing is substring but that would be the same as mid in which case you woul need to do if statements to find out how long the string is and the substring it accordingly.
Not exactly sure what you are trying to do could you explain again.
if you had and account number that needed to be 6 characters long. and the user types in 123, but you would need to display it/ store it as 000123 in VB
sacc="123"
you would just sacc= right("000000" & sacc,6)
sacc = 000123
how would you do that with javascript
hope that is better.
You could use the slice function http://www.devguru.com/Technologies/...ing_slice.html but there is no direct conversion of right.
thanks, i thought as much.
what is the definitions for the substring()
ie mid(string,(start),(for the len of)
as i am getting wierd stuff back from my substring just doesnt seem to want to follow a rule