AxISQS
asked on
JavaScript alert, needs to pause for 3 seconds
Hello,
I'm troubleshooting a JavaScript function which performs a database lookup to generate a number in a form text box. Sometimes the data generated is missing some information which we believe could be resolved by delaying things a few seconds. To overcome this we added:
This seems to help but sometimes the issue presents itself.
What can be done to make the alert last for 3-5 seconds. Like not allow the user to click OK during that time. Is that possible? Thanks in advance for your help!
I'm troubleshooting a JavaScript function which performs a database lookup to generate a number in a form text box. Sometimes the data generated is missing some information which we believe could be resolved by delaying things a few seconds. To overcome this we added:
alert('Please wait while we generate a new Document Number');
This seems to help but sometimes the issue presents itself.
What can be done to make the alert last for 3-5 seconds. Like not allow the user to click OK during that time. Is that possible? Thanks in advance for your help!
function generateDocumentNumber(){
<!-- find the workflow ID -->
var str = document.getElementById('LL_FUNC_VALUES').value;
// alert(str);
// str ="&workid=1957064&subworkid=1957064";
var workflowID = str.match(/&workid=(\d*)&subworkid/).pop();
var docNumber = '';
var docType = document.getElementById('_1_1_18_1').value;
if (docType == 'Form')
{
docNumber='E-1'+workflowID;
}
else if (docType == 'Policy')
{
alert('You must change the Document Type from Policy to either Group Policy or Corporate Policy before generating a document number.');
}
else if (docType == 'Corporate Policy')
{
//alert('Policy');
<!-- get the policy group info -->
var policyGroup = document.getElementById('_1_1_61_1').value;
if (policyGroup == '' || policyGroup == '< none >') {
alert('You must select a Policy Group Number before generating a document number.');
}
else
{
policyGroup = policyGroup.substring(0,policyGroup.indexOf(' -'));
document.getElementById('HIDDENPolicyNumber').value=policyGroup;
<!-- get the policy level value - main or supporting -->
var policyLevel = document.getElementById('_1_1_53_1').value;
if (policyLevel == 'Main'){
docNumber='AI-POL-'+policyGroup+'.000';
}
else {
GenericLivelinkLookup(
'lookupPDMSGetMaxSubPolicyNumber',
'HIDDENPolicyNumber,String',
'PolicyNumber,HIDDENPolicyNumber|MaxSubPolicyNumber,HIDDENMaxSubPolicyNumber',
undefined,
undefined,
'{ot:OTvar_livelink_cgiPath}' );
alert('Please wait while we generate a new Document Number');
docNumber='AI-POL-'+policyGroup+'.'+document.getElementById('HIDDENMaxSubPolicyNumber').value;
}
}
}
else
{
docNumber='DOC-1'+workflowID;
}
document.getElementById('_1_1_5_1').value=docNumber;
}
What is generating the document number? It would probably be best to generate that number on a separate blank page and call that number via ajax/jquery and hold off loading the rest of the content until the response from ajax is available.
ASKER
I don't know a thing about ajax and jquery cannot be used in this solution.
If I can stall the alert box for a few seconds, the issue will be resolved.
Sometimes we get the data, sometimes we do not. It's specifically isolated to HIDDENMaxSubPolicyNumber
docNumber='AI-POL-'+policy Group+'.'+ document.g etElementB yId('HIDDE NMaxSubPol icyNumber' ).value;
When it works the number is generated as Sub1249.443
When it doesn't work, everything after the decimal is missing: Sub1249.
Any ideas?
If I can stall the alert box for a few seconds, the issue will be resolved.
Sometimes we get the data, sometimes we do not. It's specifically isolated to HIDDENMaxSubPolicyNumber
docNumber='AI-POL-'+policy
When it works the number is generated as Sub1249.443
When it doesn't work, everything after the decimal is missing: Sub1249.
Any ideas?
Hi,
It looks like your code is ultimately calling the OpenText product Livelink (or Content Server):
A possible solution is to get the LL Module or LAPI code to return a 'done' flag when the search/Livelink query has completed (the '{ot:OTvar_livelink_cgiPat h}' is a Livelink Search query string).
The comment by Padas above is related to this - the LAPI/Module call would be performed from the separate page.
Without any further details, it is difficult to suggest anything further.
It looks like your code is ultimately calling the OpenText product Livelink (or Content Server):
...
GenericLivelinkLookup(
'lookupPDMSGetMaxSubPolicyNumber',
'HIDDENPolicyNumber,String',
'PolicyNumber,HIDDENPolicyNumber|MaxSubPolicyNumber,HIDDENMaxSubPolicyNumber',
undefined,
undefined,
'{ot:OTvar_livelink_cgiPath}' );
...
We would need to see the details of the 'GenericLivelinkLookup()' function. This is *probably* calling either a Livelink URL directly, or perhaps passing parameters to a LAPI utility.A possible solution is to get the LL Module or LAPI code to return a 'done' flag when the search/Livelink query has completed (the '{ot:OTvar_livelink_cgiPat
The comment by Padas above is related to this - the LAPI/Module call would be performed from the separate page.
Without any further details, it is difficult to suggest anything further.
>jquery cannot be used in this solution.
Is this because you don't know it or don't want to load it?
You can use pure javascript for ajax without using jquery. Loading jquery today is very common and v2 is lighter because it does not support older ie.
Is this because you don't know it or don't want to load it?
You can use pure javascript for ajax without using jquery. Loading jquery today is very common and v2 is lighter because it does not support older ie.
You could launch the alert with a delay:
setTimeout("alert('Please wait while we generate a new Document Number')", 5000);
setTimeout("alert('Please wait while we generate a new Document Number')", 5000);
ASKER
Yes, this is Livelink. I am not going to introduce jquery into my application. I need to achieve this with gold old fashioned javascript.
What Say1973 suggests is almost exactly what I need.
When I implemented setTimeout, the number generated immediately in the text box, missing the digits after the decimal (the exact issue I'm trying to avoid). Then the pop-up occurred as the js function instructed.
What I'd like is for the timeout to occur before the text is generated in the text box. I thought it would but it didn't.
Is there a way to pop-up alert immediately but grey out the OK button for 5 seconds?
What Say1973 suggests is almost exactly what I need.
When I implemented setTimeout, the number generated immediately in the text box, missing the digits after the decimal (the exact issue I'm trying to avoid). Then the pop-up occurred as the js function instructed.
What I'd like is for the timeout to occur before the text is generated in the text box. I thought it would but it didn't.
Is there a way to pop-up alert immediately but grey out the OK button for 5 seconds?
Unfortunately, I don't know any.
Hi,
You could try something like this:
Cheers
You could try something like this:
<html>
<head>
<title>delay popup</title>
<script type="text/javascript">
function popup()
{
var popup = window.open('','popupwin','height=200,width=300,toolbar=none');
popup.document.write("<html><title>Delay OK</title>")
popup.document.write("<body style='background:#ccc;'>")
popup.document.write("<div>Test countdown</div>")
popup.document.write("<div id='timer'></div>")
popup.document.write("</body>")
popup.document.write("</html>")
popup.onload = function()
{
try
{
popup.document.getElementById("timer").innerHTML = '<input disabled="disabled" type="button" value="OK" onclick="javascript:window.close();" />';
popup.setTimeout(function(){popup.document.getElementById("timer").innerHTML = '<input type="button" value="OK" onclick="javascript:window.close();" />'},3000);
}
catch(e)
{
alert(e)
}
}
popup.document.close();
}
</script>
</head>
<body>
<a href="#" onclick="popup();">TEST</a>
</body>
</html>
Basically, it creates a new HTML window that simulates an OK dialogue with a delay. This should get you going with what you want.Cheers
ASKER
Thanks smeghammer I'll give that a shot. How would I implement this where the last alert exists in my code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What is happening that you are only sometimes getting part of the data?
Is this an ajax call?
Seems more like you need to optimize the code if it is taking too long to execute and pass the data back.