Jump to content

javascript help!!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
9 replies to this topic

#1
Guest_aicirt_*

Guest_aicirt_*
  • Guests
im kinda unsure where this post should go... but here goes...

right now i have these 2 text fields...


<%if v_cnt mod 2 = 0 then%>

<td align="center"><INPUT type="text" name=txtClockTime maxlength=5 size=5 value="<%=formatdatetime(v_HistTime,4)%>" style="font-family : Tahoma, Sans-Serif, Verdana, Geneva, Arial, Helvetica; background:#F2F5FE; font-size : 8pt; color: #31345C"></td>

<td width="11"><img src="/images/control/eTimeClock/div.gif"></td>

<%else%>

<td align="center"><INPUT type="text" name=txtClockTime maxlength=5 size=5 value="<%=formatdatetime(v_HistTime,4)%>" style="font-family : Tahoma, Sans-Serif, Verdana, Geneva, Arial, Helvetica; background:#F2F5FE; font-size : 8pt; color: #31345C"></td>

<td width="11"><img src="/images/control/eTimeClock/div.gif"></td>

<%end if%>


and i have this function to check for it...


function ValidateTime(){

// Checks if time is in HH:MM format.

//Clock-in time 

var i = 0	

timeStr = document.Report.txtClockTime(0).value;

var timePat = /^(\d{1,2}):(\d{2})?$/;

var matchArray = timeStr.match(timePat);

if (matchArray == null) {

alert("Clock-In time must be in a valid format(HH:MM).");

return false;

}

hour = matchArray[1];

minute = matchArray[2];


if (hour < 0  || hour > 23) {

alert("Clock-In hour must be between 0 and 23.");

return false;

}


if (minute<0 || minute > 59) {

alert ("Clock-In minute must be between 0 and 59.");

return false;

}

    

//Clock-Out time 

i = 1

timeStr = document.Report.txtClockTime(1).value;

	

var timePat = /^(\d{1,2}):(\d{2})?$/;


var matchArray = timeStr.match(timePat);

if (matchArray == null) {

alert("Clock-Out time must be in a valid format(HH:MM).");

return false;

}

hour = matchArray[1];

minute = matchArray[2];


if (hour < 0  || hour > 23) {

alert("Clock-Out hour must be between 0 and 23.");

return false;

}


if (minute<0 || minute > 59) {

alert ("Clock-Out minute must be between 0 and 59.");

return false;

}

	

                var sClockin  = document.Report.txtClockTime(0).value

                var sClockout  = document.Report.txtClockTime(1).value

		

	sClockin = sClockin.replace(/:/gi,"");

	sClockout = sClockout.replace(/:/gi,"");

		

	if (parseInt(sClockout) < parseInt(sClockin))

	{

		//alert(parseInt(sClockout));

		//alert(parseInt(sClockin));

		alert ("Clock-Out time must be greater than or equal to Clock-In time");

		return false;

	}

}


it's actually some kind of clocking system that allows people to clock in and out to keep track of their working hours and stuff... right now it only checks for 1st set of clock in and out... i wanna change it such that it checks for more than the 2 entries in cases where there are multiple entries and i dont know how... desperate for help =(

#2
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
Hey aicirt, I'm not sure what you mean that you want it to check for two clock-in and clock-out. If the same users clocks-in twice, is that what you want to check?

#3
Guest_aicirt_*

Guest_aicirt_*
  • Guests
yeah something like that. like when a user clock in for work. clock out for lunch. clock in after lunch. clock out after work.

Clock in : 08:00
Clock out : 12:00
Clock in : 13:00
Clock out : 18:00

this would be a case of more than 2 entries...

#4
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
I've looked over the function you sent and all that function does it validate that a valid time is entered. You must have left something out above. Is there more functions and is there a server side language like PHP storing the values?

#5
Guest_aicirt_*

Guest_aicirt_*
  • Guests
do u mean this ?


if Request.Form("sbUpdate") <>"" then

		

	v_SelectedId=Request.Form("HdnUserGUID")

	v_SelectedDate=Request.Form("cmbYear") & Request.Form("cmbMonth") & Request.Form("cmbDay")

	

	v_SqlHistory="select time_in,time_out,user_operation,time_in_act,id from etimeclock_data where gu_id='" & v_SelectedId & "' and company_id='" & v_CompanyId & "' and (convert(varchar(8),time_in,112)='" & v_SelectedDate & "' or convert(varchar(8),time_out,112)='" & v_SelectedDate & "')"

	rsHistory.Open v_SqlHistory,Application("econn"),3,1,1 

		

	v_Count=1

	do while rsHistory.EOF =false 


		if Request.Form("txtClockTime").Item(v_Count) <> "" then

		

			if rsHistory("user_operation") = "i" then

				tmpDate	= formatdatetime(rsHistory("time_in"),2)

				tmpField= tmpDate & " " & Request.Form("txtClockTime").Item(v_Count)

				v_arrSqlQuery="update etimeclock_data set time_in='" & tmpField & "' where gu_id='" & v_SelectedId & "' and company_id='" & v_CompanyId & "' and convert(varchar(8),time_in,112)='" & v_SelectedDate & "' and id='" & rsHistory("id") & "'"

			else

				tmpDate	= formatdatetime(rsHistory("time_out"),2)

				tmpField=tmpDate & " " & Request.Form("txtClockTime").Item(v_Count)

				v_arrSqlQuery="update etimeclock_data set time_out='" & tmpField & "' where gu_id='" & v_SelectedId & "' and company_id='" & v_CompanyId & "' and convert(varchar(8),time_out,112)='" & v_SelectedDate & "' and id='" & rsHistory("id") & "'"

			end if

			

			arrSql(v_Count)=v_arrSqlQuery

		end if

		v_Count=v_Count+1

		rsHistory.MoveNext

	loop


end if



#6
Guest_Jordan_*

Guest_Jordan_*
  • Guests
If you can either attach your entire program/website here or send it to me via email or PM I'll have a look at it and try to get it working the way you like.

#7
Guest_aicirt_*

Guest_aicirt_*
  • Guests
id love to... but the code is duper long it scared the system out. i cant pm you and u didnt enable email. so... ya =\ :(

#8
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts
I don't see enough code to give you a definitive answer, but it looks like your problem is that you're doing an update statement:

v_arrSqlQuery = "update etimeclock_data set time_in='" & _

   tmpField & "' where gu_id='" & v_SelectedId & "' and company_id='" & _

   v_CompanyId & "' and convert(varchar(8),time_in,112)='" & _

   v_SelectedDate & "' and id='" & rsHistory("id") & "'"

You'd want that to be an INSERT statement. I suspect this would involve some database changes as well, though. I'm a little unclear on the logic of the snippet, but it looks like you actually insert more than 1 time value? And, depending on what the last operation was, you do a clock in/clock out?

Also, while it's not really relevant to your problem, I have to point out that your concatenated sql strings are ripe for a sql injection. If this is only used by trusted users, you'll probably be ok - but you may want to read up on sql injection for your next project.

#9
Guest_Jordan_*

Guest_Jordan_*
  • Guests

aicirt said:

id love to... but the code is duper long it scared the system out. i cant pm you and u didnt enable email. so... ya =\ :(

You should be able to PM me fine. Click on my name and then "Send Private Message"

#10
Guest_aicirt_*

Guest_aicirt_*
  • Guests
yah the codes too long to fit in to PM that's wad i meant ... :(