Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Javascript Modal Boxes / or pause script

Status
Not open for further replies.

vicvirk

Programmer
Feb 4, 2009
636
CA
I posted this in the VBScript forum but got nowhere, managed to write something that works in javascript, but now I have another issue.

We have an application that prompts the user for an input using

Code:
strReason = prompt('enter reason');

A request came in to replace the text input box with a drop down list. I knew i couldn't do this with a regular Modal Box so I put the functionality into a pop-up. The user selects a reason from the drop down and that value is passed back to the opening window and the script takes over from there.

Here's where it gets tricky...

The page is written with over 1000 lines of vbscript (client side) and the prompt is called as follows:

Code:
do while strReason = ""
strReason = InputBox("enter reason")
if strReason = "" then
  msgBox("You must enter a reason")
end if
loop
...do something with strReason

What I've done is created a javascript function that opens a window, takes the value that was entered and passes it back to a hidden text field on the original window and strReason reads from this text field.

The VBScript
Code:
winNew = openWin() ' this is a javascript function
strReason = tbxSelValue.value

The JavaScript
Code:
//global 
var winRef;
var isOpen;

function openWin() {
	winRef = window.open("selectReason.html","selWindow","toolbar=no,width=250...");
	isOpen = true;
	for (var i = 0 ; isOpen ; i++)
		isWindowOpen()
		
	return true;
}
function isWindowOpen() {

	if (!winRef.closed) {
		wait(100);
		isOpen = true;
	} else {
		isOpen = false;
	}
}


function wait(msecs)
{
	try {
		var start = new Date().getTime();
		var cur = start
		while(cur - start < msecs)
		{
		cur = new Date().getTime();
		} 
	} catch (e) { return true; }
}

So, my issue is with the wait() function - which is basically a pause function I picked up of the web...that recursion is causing the script to timeout on some of our older machines and I need a way to stop executing the script in the background until that pop up window is closed (which is what a standard model box does). The rescusion is required so that the vbScript does not continue.

The other thing is that there are about 28 different reasons that need to be collected so the pop up will appear 28 times (once for each reason).

I've put what I have so far (in a pick-a-month) example where you are prompted to pick three months and once you are complete, the three months will display. You can see that here:


Anyone have any ideas? Is is possible to create a custom modal box that works the same way as a prompt(), alert() or confirm()???? Although it would be great if someone gave me code to get started, it would also be great if someone can help me find a good tutorial on how to do this - I've been looking but can't seem to find anything.

Unfortunatley, re-writing it is not an option, but dropping the project might be. There are 1000's of lines (no kidding) of vbScript written and although we are in the process of re-visiting this one page and potentially re-writing it, we're a few months away from even getting started. If it is possible to do what I need, it will have to be incorporated into what we have and we can do it better if/when we get to the full re-write.

Thanks...




TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
If you post the question to vbs forum, let me see if I can help. Otherwise, I am reluctant to do a semantic analysis with the mixing of js and vbs in the middle.
 
Tsuji,

I posted it in the VBScript forum under the title "Detect Window Close"


Thanks - look forward to any insight you might have...



TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
First it is a wide-post, second it is a long thread. I don't read long thread, which often means incompetence of un-identified parties. Post a concise question if you're interested. I guess, people just answer their own question, and that's good.
 
This is as concise as I can get...

I need to build a custom modal box that behaves the same way as an alert(), prompt() or confirm() modal box ("pauses" the script while the box is open). The custom modal box needs to have drop down options + an open text field for "Other".



TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
feherke, I've tried that and couldn't find anything that's why I posted a msg here...

Also, all the examples out there for Modal Windows are not real modal windows, they are rather css'ed version that overlay on the screen - this won't work as the script behind will continue to run...

screw it - I don't think it's possible to do what I am attempting - I'll have to find another method...

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Hi

vicvirk said:
Also, all the examples out there for Modal Windows are not real modal windows, they are rather css'ed version that overlay on the screen
Correct. Those are the ones which work in all modern browsers.
vicvirk said:
this won't work as the script behind will continue to run...
If you want that, I would say it is a software design issue. GUIs are typically multi-threaded. You should rethink your code and split it on threads, then bind each piece to the matching event.

What you want to be executed after the modal [tt]div[/tt] is closed, just put it in a function and set it to be called after the [tt]div[/tt] is closed. ( You will have to check which of the solutions provide such event handler. For example GreyBox's [tt]GB_show()[/tt] has a callback function parameter. )

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top