PDA

View Full Version : Run a Javascript in the background



terp_in_umcp
08-17-2007, 01:39 AM
Hi there...dunno if this is an asp or javascript question....

I have an asp page with a Alert function...Once the client puts in an Alert from a website, the sql table gets updated on our end with the note...Now when I come in say next morning, I should get a popup of the Alert and be able to snooze it...once snoozed for say 5 mins...it should automatically popup after 5 mins....

Right now I am using an onload function that calls a javascript that does the job...however if I dont reload the page at tht time, then it doesnt seem to popup...so basically I am looking for a javascript or some function that can run in the background and keep looking if the Alert is present or if it is snoozed....

Thanks,

Here's some bits of my code:

TOPPAGE.asp

<script language="JavaScript" type="text/javascript">

<!--

function Loadingfunc() {
var y = window.setTimeout("something();", 1);

}
//-->
</script>

=====================================================

<script>

function something()
{

<%
mySQL = "Select * from FMSAlerts where AlertCompletedon is null and AlertType='CLT' and (datediff(mi,getdate(), Snoozed)<5 OR Viewed is null) and Accountnumber in (Select number from notes where Action='Client' and number in (Select number from master where desk='"&Users("DeskCode")&"'))"
Set ClientAlerts=Con.Execute(mysql)

%>

<% if ClientAlerts.eof<>true then %>

-------------Code to open a fading popup window------------

var w, h, l, t;
w = 400;
h = 200;
l = screen.width/4;
t = screen.height/4;

window.scrollTo(0,0);
DropDown.style.width="20%";
DropDown.style.height="10%";
DropDown.style.margin="0px 20px 20px 40%";
displayFloatingDiv('DropDown', 'Floating and Dimming Div', w, h, l, t);
DropDown.style.display="Block";

------------------------------------------------------------------------

ajaxpage('CollectionReminders.asp?ReturnData=ClientAlertPopup', 'DropDown');

<% else%>

//alert("No");

<% end if%>




}
</script>


=======================================================

COLLECTIONREMINDERS.ASP

<%if Request("ReturnData")="ClientAlertPopup" then %>

<div id=PopScroll>

------------code to stamp a date viewed on all accounts that satisfy the condition-----------------------------

<%
mySQL = "SELECT Distinct number FROM notes Where number in (Select number from master where desk='"&Users("DeskCode")&"') and Action='Client' and Uid in (SELECT AlertCrossRef FROM FMSAlerts where AlertCompletedon is null and AlertType='CLT')"
Set ClientAlerts1=Con.Execute(mysql)



%>

<% do while ClientAlerts1.eof<>true %>

<%
mysql="Select * from FMSAlerts where AlertCompletedon is null and AlertType='CLT' and Accountnumber='"&ClientAlerts1("number")&"'"
Set GetClientRecord1=Con.Execute(mysql)

mysql="UPDATE FMSAlerts SET Viewed='"& Now()&"' WHERE AlertID='"& GetClientRecord1("AlertID")& "'"
Con.Execute(mysql)
%>

<%
ClientAlerts1.movenext
loop

%>






<table width=98% bgcolor=Silver>
<tr>
<td class=Header4 width=96% colspan=3>


</td>
<td class=Header4 width=4% > <img src="images/Close.gif" onClick="HideDropDown();" align=Right/></td>
</tr>

</table>

<table width=98% bgcolor=Silver>
<form name="Snoozeform">
<tr>
<td align=center class=List1 width=1% colspan=5><p>You have a Client Alert!!!</p></TD>
</tr>
<tr></tr>

<tr>

<td align=center>
<input type=button class=List1 onClick="ViewClientAlerts();" value="VIEW">

<select name=SnoozeTime class=List1 onchange="SnoozeClientAlerts(this.value);">
<option>Snooze</option>
<option value='5'>5 mins</option>
<option value='10'>10 mins</option>
<option value='15'>15 mins</option>
<option value='30'>30 mins</option>
</select>


</td>


</tr>

</form>
</table>

<%if request("Snooze")="yes" then %>

-------------code to snooze all accounts tht satisfy the condition------------
<%
mySQL = "SELECT Distinct number FROM notes Where number in (Select number from master where desk='"&Users("DeskCode")&"') and Action='Client' and Uid in (SELECT AlertCrossRef FROM FMSAlerts where AlertCompletedon is null and AlertType='CLT')"
Set ClientAlerts2=Con.Execute(mysql)


%>

<% do while ClientAlerts2.eof<>true %>

<%
mysql="Select * from FMSAlerts where AlertCompletedon is null and AlertType='CLT' and Accountnumber='"&ClientAlerts2("number")&"'"
Set GetClientRecord2=Con.Execute(mysql)


mysql="UPDATE FMSAlerts SET Snoozed=DATEADD(minute,"&Request("SnoozeTime")&",'"&GetClientRecord2("Viewed")&"') WHERE AlertID='"& GetClientRecord2("AlertID")& "'"
Con.Execute(mysql)
%>

<%
ClientAlerts2.movenext
loop

%>


<% end if %>





</div>

<% end if %>

miranda
08-17-2007, 05:21 AM
This definately needs to be done client side since the server side code is done processing long before the button will be clicked on the alert. I am not a javascript guru but I would think that you would probably do better with a modal dialog than with the alert as it might be easier to capture the event of the button click and start the timer off of it.