Jump to content

Recommended Posts

i have window.open open a window letting the user know that something is going on when the submit button is clicked. The script takes about 10 seconds to run. I am having problems getting the window to close after the PHP script is finished. Any input would be greatly appreciated.

Am I able to call a javascript function before the script is ran, and then after the script is done, run another js function?

 

ex:

<?php

js function          before running script

script stuff here

js function          after script is finished

?>

 

If this gets to off topic, I have this posted in the js section also.  I just wanted to give gergy008 a response. Sorry for the double post. Let me know if I have to close this one down.

Yes this is the wrong section, as this is a javascript problem, but you are probably looking for something along the lines of

window.close();

 

look it up on google. Although, I think if you try to close the main browsing window, it will throw a message. Why do you want to close the browser anyways?

i'm not looking to close the browser or the main page the user is on. Here it is again.

the user goes to an upload page, they hit submit to upload, a popup window displays letting them know that something is happening, when the script is done uploading they are taken to a new page and the popup window is to be closed. it is just the popup window that I want to open before the script and then close after the script. I have searched everywhere on google and cannot find a way to do this. And ok, i'll continue this is js section

You don't need to have a popup. Most browser block them anyway...

 

The JavaScript:

function upload(formdiv, messagediv){
var formID = document.getElementById(formdiv);
var messID = document.getElementById(messagediv);
formID.style.display = 'none';
messID.style.display = 'block';
}

 

The HTML:

<div id="form">
<form action="post_somewhere.php" method="post" enctype="multipart/form-data">
	<p><label for="file">File:</label> <input type="file" name="somename" id="file" /></p>
	<p><input type="submit" value="Submit!" onclick="upload('form', 'message');" /></p>
</form>
</div>
<div id="message" style="display:none;">
<h1>Uploading...</h1>
<p>
	Please wait, your file is uploading. Do NOT refresh the page, the page will refresh on it's own.
	Larger files will take longer to upload, please be patient.
</p>
<p>
	Thanks!
</p>
</div>

That is the way that I originally had the page setup. But I also have some validation that is done before the upload. Right now, with the setup you suggested, when the user hits the submit button and has something wrong filled out, the please wait div still pops up.

I need to call the function inside of the upload script file, and the javascript needs to be ran before the php script so the message is displayed for the user while they are waiting. So is there something I could do inside of the PHP upload script to display the wait message?

at the beginning of my script I tried something like this.

echo "<script type='text/javacript'>
function upload(message_box)
{
var messID = document.getElementById(message_box);
messID.style.display = 'block';
}
upload(message_box);
</script>";

But nothing happens.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.