Solved

JavaScript alert, needs to pause for 3 seconds

Posted on 2013-10-25
11
426 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
ID: 39601150
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
ID: 39601207
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
ID: 39601308
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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 4

Expert Comment

by:smeghammer
ID: 39603720
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
ID: 39603977
>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
 
LVL 9

Expert Comment

by:Sar1973
ID: 39605010
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
ID: 39606655
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
ID: 39608280
Unfortunately, I don't know any.
0
 
LVL 4

Expert Comment

by:smeghammer
ID: 39608326
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
ID: 39608375
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
ID: 39608586
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

679 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