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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Js to <body> to Js, how can I do this? 1

Status
Not open for further replies.

hitsuin

Vendor
Aug 23, 2010
24
GB
Hi everyone, I'm trying to get something like like "please wait" displayed in place of my result while the js is functioning to show that the javascript is working.

I'm guessing it needs to go to the body before automatically going back to the script block for the final function. I've been trying for a few days to get this to work but figure it out. Can anyone help me?

Here's the code to show what I mean.

Code:
<html><head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">

<script type="text/javascript">

function JavaProcessAlert()
				{
			var Update = document.getElementById('DisplayedText') 
			Update.innerHTML = "Please wait" ;			
				}


function JavaProcess()
				{
			var xx = 0;
			while ( xx < 1000000000 ) { xx++; }
			Update.innerHTML = xx;
				}
    </script>
</head>
<body>
<p id="DisplayedText" >Get Result</p>
<p><input value= "Start" onclick="JavaProcessAlert();" type="button"></p></form>

</body></html>
 
Assuming this is just a place holder of your actual code, why not simply call your alert before your code in your function.

Code:
function JavaProcess()
                {
            [red]JavaProcessAlert();[/red]
            var xx = 0;
            while ( xx < 1000000000 ) { xx++; }
            Update.innerHTML = xx;
                }

You could even simply call it before calling your process function:

Code:
<input value= "Start" onclick="JavaProcessAlert(); JavaProcess();" type="button">


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
I actually tried that prior to making this thread. The reason why I can't use those is because the whole point is while the second function, JavaProcess() is working, for the duration of its function, "Please wait" is displayed on the page. So far, the page either stops at "Please wait" or jumps straight to the result. Both of which defy the point, if that makes sense.
 
How are you calling your process?

So far, the page either stops at "Please wait" or jumps straight to the result

This only makes sense if your alert function has an error that stops the script, or if your script is fast enough so that the please wait message gets immediately overwritten.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
This one, the last decent one I tried before I turned to this forum, stops at "please wait."

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">

<script type="text/javascript">



function JavaProcessAlert()
				{
			var Update = document.getElementById('DisplayedText') 
			Update.innerHTML = "Please wait" ;			
				}


function JavaProcess()
				{
			var xx = 0;
			while ( xx < 1000000000 ) { xx++; }
			Update.innerHTML = xx;
				}
    </script>
</head>
<body>
<p id="DisplayedText" >Get Result</p>
<p><input value= "Start" onclick="JavaProcessAlert(); JavaProcess();" type="button"></p></form>

</body></html>

Whereas this one, which I got from you and is funny because prior to this I tried it the other way around, also stops at please wait.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">

<script type="text/javascript">



function JavaProcessAlert()
				{
			var Update = document.getElementById('DisplayedText') 
			Update.innerHTML = "Please wait" ;			
				}


function JavaProcess()
                {
            JavaProcessAlert();
            var xx = 0;
            while ( xx < 1000000000 ) { xx++; }
            Update.innerHTML = xx;
                }
    </script>
</head>
<body>
<p id="DisplayedText" >Get Result</p>
<p><input value= "Start" onclick="JavaProcess();" type="button"></p></form>

</body></html>

I don't know what I'm doing wrong or how to get around it. If it were that it goes so quickly because it goes straight to the result that would be one thing, but thats not the case, the process takes time and I need a there to be feedback that its working during the wait.
 
you have
var Update
within JavaProcessAlert

but within JavaProcess,
you try to use Update directly
Update is not available within JavaProcess
as it is only available within JavaProcessAlert's scope
 
I wrote it badly for this but thats one thing I did try it before. Its what I was writing about earlier about how it jumps straight to the result and never shows "please wait" for the time it takes to work. It shows "Get Result" for the time it takes to work and then probably "please wait" for a fraction of a second and then the actual result.

If you try it, you'll see what I mean.
 
Try this instead:
Code:
<input value= "Start" onclick="JavaProcessAlert(); setTimeout('JavaProcess()',100);" type="button">
[code]

This gives the alert function just enough time to write out the Please Wait message before initiating the other function.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown. 

Behind the Web, Tips and Tricks for Web Development. 
[URL unfurl="true"]http://behindtheweb.blogspot.com/[/URL]
 
This is exactly why I always find myself clicking "Thank vacunita for this valuable post!" :p

I just did again, thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top