Jump to content

pausing page loading till javascript confirm has been executed?


blueman378

Recommended Posts

hi guys, well heres my code:

<?php $dual = 0; 
$upload = "filename"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<SCRIPT LANGUAGE="JavaScript">
function overwrite()
{ 
var response = confirm('The file "<?=$upload?>" already exists would you like to overwrite?');
if (overwrite) <?php $overwrite = 1; ?>; else <?php $overwrite = 0; ?>;}</SCRIPT>
</head>
<?php if ($dual == "1") { ?>
<body onload="overwrite()">
<?php }
else { ?>
<body>
<?php }
echo $overwrite; ?>

 

which works a bit, but i want the page to stop loading, that includes the server side stuff, till the javascript confirm has been run, is this possibnle?

 

cheers

Link to comment
Share on other sites

Adding the a script tag will stop processing the page, so adding the confirmation in the head (you almost have it) will do the trick.

 

Just remove the function so the confirm message shows up right away.

 

The main issue is PHP runs before JavaScript exists, so you'll need to redirect the user to the overwrite page (not in the same page) If they want to over write the file. Here are a few option

 

upload the file with a temporary name (ie time of upload) and if exists ask the user to overwrite or rename. The next page will take the file and change it.

 

Give the user the option to overwrite if exists before they upload the file. If they didn't check it and it exists, return an error the file already exists.

 

<SCRIPT LANGUAGE="JavaScript">
var response = confirm('The file "<?=$upload?>" already exists would you like to overwrite?');
if (response) {
    location.href = "confirm_overwrite.php?ID=SOME_ID_TO_IDENTIFY_THE_FILE";
}
// otherwise show the page with a new name
</SCRIPT>

Link to comment
Share on other sites

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.