View Full Version : Nested Function Calls Problem
04-10-2003, 06:37 PM
I have a JS calculator and after each calculation the user makes I re-create the displaying Frame from another Frame where I keep the code and keep track of variables. The function makeImage() re-creates the displaying Frame.
The calculator has a search feature which searches for items from a database for the user to calculate. After the user completes a search, the displaying Frame is re-created with makeImage() to display the results of the search. It basically displays the contents of a variable named searchDisplay.
A search can take some time, so I got the clever idea to display the text "Searching..." while the computer was working away. It was the easiest code I ever wrote! At the start of the search function I simply inserted:
Then as the search function runs it re-creates searchDisplay with the search results and then calls makeImage() again to display searchDisplay -- the results of the search.
Easy code, but it fails. It never displays.
Funny thing is I put in alert(searchDisplay) after the above two lines of code and when the computer pauses to display the alert message I see "Searching..." displayed in the background. But without the alert it never shows.
The code is basically:
... search and put results in searchDisplay
Again, it works perfectly with the alert in there after the first makeImage().
If the search were very short, I'd think it might be flashing by so quickly I never see it. But a search can take over 5 seconds so that's not the reason.
04-10-2003, 07:39 PM
got a link?
04-10-2003, 08:21 PM
I put a test version here:
All you have to do is click on search, or maybe enter something like fruit then click on search. It's working with the alert.
I thought it might be a problem with timing, so I split up the search function. The first part function Search() displays my little message, then it calls the second part function Search2() which completes the search function and displays the results. It didn't help. It still only works with the alert message.
04-10-2003, 08:48 PM
Hmm. I'm not sure, but if the alert() fixes it, then you have a timing issue. Try using a setTimeout for 50ms or so.
04-10-2003, 08:54 PM
Hmm, I never liked the leakyness of setTimeout, and the asynchronousy. Try this:
delete top._;It should give you a delay of 50 milliseconds. Edit the number as you see fit.
04-10-2003, 09:05 PM
I tried both methods putting the code right were the alert was and it didn't help. Actually, with Liorean's I got an error message, "Object doesn't support this code."
Seems funny that it's a timing problem.
If the search were really fast, it could be. But the page can certainly be re-created and displayed during a long search time. Unless the computer is busy doing the search. That's why I tried splitting the function, so it clearly did 1. re-create the page then 2. search function. Which didn't help. ???
Come to think of it, all other times I re-create the page I then do nothing. Waiting for the user's next move.
Hmm. That seems to make it obvious. It doesn't like being told to re-create the page then do something else. Guess I need:
kinda like an onLoad. Wish we could just make things up. (Actually, that's what I do all the time and so I'm always fixing stuff! Haha.)
04-10-2003, 09:08 PM
Well, we'll try to simplify, then:
var nTime=new Date;
That shouldn't cause any object problems.
04-10-2003, 09:08 PM
Another nutty idea to try... I do this all day long...
I'll put the call to function Search2() and then end of makeImage() instead at the end of function Search(). So it won't be called immediately. Search2() will be called at the end of makeImage().
Anyway I'll try this and post back.
04-10-2003, 09:34 PM
Nothing has helped except the alert.
I put the call to continue the search function at the very end of makeImage... even after the document.write but it didn't help. I guess it needs time to complete the document.write.
I'll play with it another day with a fresh mind. (Though not likely any smarter!)
04-10-2003, 09:41 PM
Could you not connect the second run of the function to the onload handler of the frame? That should provide you with what you need.
04-10-2003, 09:52 PM
I just did that... before I got your note, actually.
Yes, it seems to work.
I'm getting the display I want then instead of the search continuing I'm getting an error message object expected but I'm sure I can resove that.
04-10-2003, 11:27 PM
My error was leaving off a parent.create but it didn't matter. Even the onLoad doesn't work. (In my previous post I said it did... the error message had the same effect as an alert... stopping the computing causes the display I want to display to display.)
Ignoring the anomaly that for some reason inserting an alert seems to make things work, I believe I can state the problem. At least for my IE browser.
The browser simply does not do anything affecting the display until it has finished all computing. Thus I will always fail trying to display a message saying that I am computing. Or, in my case, searching.
I got another idea. A better one than the original, actually. I use rollovers to play with button images and have a button that is a spinning arrow. So I decided instead of re-creating the display with different text to simply do a button change. I do that all the time without re-creating the display.
I put the call to the function to change the button at the start of Search() and it still failed. Next I tried putting it in the code for the button. On onClick I changed to the spinning arrow. Worked great. Then, doing things in baby steps, on onClick it changed to the spinning arrow then called Search().
It just won't do the button change till the search computing is done and then the display is all different anyway.Too late.
Last idea! You can always change the display of an <input type=text easily. Wrong!
It won't even do that with computing (searching) code following.
So I give up... thinking with my little mind that I have worked out the logic and it's really not possible.
Thanks for the help with this.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.