|
-
Jul 18th, 2003, 05:48 AM
#1
Thread Starter
Addicted Member
Javascript equivilant
Can someone please tell me what the the Javascript equivilant of this VB Code is
I want to lose the decimal places.
Thanks
-
Jul 18th, 2003, 06:54 AM
#2
Frenzied Member
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.
-
Jul 18th, 2003, 07:09 AM
#3
Thread Starter
Addicted Member
Thanks.
But i am also getting this error:
TypeError: getField("In") has no properties
3 ocument-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....
-
Jul 18th, 2003, 07:23 AM
#4
Frenzied Member
Ok so you're passing 3 variables into the function totalTime and then trying to access these values using:
Code:
var start=getField("In").value;
var finish=getField("Out").value;
var lunch=getField("Lunch").value;
Try using
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.
-
Jul 18th, 2003, 07:44 AM
#5
Thread Starter
Addicted Member
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
-
Jul 18th, 2003, 08:14 AM
#6
Thread Starter
Addicted Member
--- 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]
Last edited by Mage; Jul 18th, 2003 at 09:44 AM.
-
Jul 18th, 2003, 10:47 AM
#7
Frenzied Member
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.
-
Jul 18th, 2003, 10:50 AM
#8
Thread Starter
Addicted Member
I managed to solve the NaN problem, thanks do you know what the equivilant of Len() is??
-
Jul 18th, 2003, 11:14 AM
#9
Frenzied Member
Len(variablename)
would be
variablename.length
-
Jul 21st, 2003, 09:10 AM
#10
Thread Starter
Addicted Member
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.
-
Jul 21st, 2003, 09:15 AM
#11
Frenzied Member
Not exactly sure what you are trying to do could you explain again.
-
Jul 21st, 2003, 09:19 AM
#12
Thread Starter
Addicted Member
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.
-
Jul 21st, 2003, 09:26 AM
#13
Frenzied Member
You could use the slice function http://www.devguru.com/Technologies/...ing_slice.html but there is no direct conversion of right.
-
Jul 21st, 2003, 09:45 AM
#14
Thread Starter
Addicted Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|