Solved

JavaScript alert, needs to pause for 3 seconds

Posted on 2013-10-25
11
360 Views
Last Modified: 2013-11-01
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:
alert('Please wait while we generate a new Document Number');

Open in new window


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 ="&amp;workid=1957064&amp;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;		 
		}

Open in new window

0
Comment
Question by:AxISQS
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 58

Expert Comment

by:Gary
Comment Utility
You cannot affect an alert box once it has been generated.
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.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
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.
0
 

Author Comment

by:AxISQS
Comment Utility
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-'+policyGroup+'.'+document.getElementById('HIDDENMaxSubPolicyNumber').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?
0
 
LVL 4

Expert Comment

by:smeghammer
Comment Utility
Hi,

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}' );
...

Open in new window

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_cgiPath}' 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.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
>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.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 9

Expert Comment

by:Sar1973
Comment Utility
You could launch the alert with a delay:
setTimeout("alert('Please wait while we generate a new Document Number')", 5000);
0
 

Author Comment

by:AxISQS
Comment Utility
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?
0
 
LVL 9

Expert Comment

by:Sar1973
Comment Utility
Unfortunately, I don't know any.
0
 
LVL 4

Expert Comment

by:smeghammer
Comment Utility
Hi,

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>  

Open in new window

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
0
 

Author Comment

by:AxISQS
Comment Utility
Thanks smeghammer I'll give that a shot.   How would I implement this where the last alert exists in my code?
0
 
LVL 4

Accepted Solution

by:
smeghammer earned 500 total points
Comment Utility
No idea -

We need to know how the Livelink system is called. Basically I think what you need is a delay BETWEEN the call from your code, and the return value of that call.

Anything you do client-side will NOT affect what Livelink is doing to generate the new docid. The only sure way to do this is to determine that the correct value is returned from the call:

CLIENT:
Call Livelink to get docid
SERVER:
does stuff that takes an arbitrary length of time
CLIENT:
does NOT know when - or even if - the server process has finished, so anything you initiate here is independent of the call to the server - as you found with the initial alert you put in.

Your initial call does not return anything, and the next statement will process regardless of whether the call to Livelink has completed:
GenericLivelinkLookup( params ); 
  alert('Please wait while we generate a new Document Number'); 

//THIS WILL EXECUTE **IMMEDIATELY** AFTER THE ABOVE CALL, EVEN IF LL HAS NOT FINISHED PROCESSING:
  docNumber='AI-POL-'+policyGroup+'.'
   +document.getElementById('HIDDENMaxSubPolicyNumber').value;

}

Open in new window

I am assuming that this function populates the field 'HIDDENMaxSubPolicyNumber. If so, if the call has not finished, the next call to assemble your docNumber will retrieve an empty field value as you have seen.

Ideally, you should modify that call to return true/false depending on whether it completes:
if(GenericLivelinkLookup(params))
{
  //generate doc number ONLY if the call has completed:
   docNumber='AI-POL-'+policyGroup+'.'
    + document.getElementById('HIDDENMaxSubPolicyNumber').value;
}

Open in new window

If you cannot do this, then the only way is to insert a delay between the call to the Livelink lookup and the next statement using the SetTimeout() method (not tested):
GenericLivelinkLookup(params);

//generate the doc number afer 3 seconds. This should be enough time for the LL call to complete and populate 'HIDDENMaxSubPolicyNumber'
setTimeout(function(){docNumber='AI-POL-'+policyGroup+'.'
   +document.getElementById('HIDDENMaxSubPolicyNumber').value;},3000); //3 seconds
//you can add my dialogue simulation here if you like, but it is probably nicer to use DOM manipulation to put a 'please wait' where your form will appear.
}

Open in new window

I have made a lot of assumptions about what is going on here, but basically, the key is the setTimeout() statement to delay execution of the step after your call to Livelink.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now