Jump to content

page redirect after function success


AceOfJames

Recommended Posts

I am trying to redirect a page to another page after a function is successful in javascript.

 

I posted about this before and just could not figure it out.

 

Here is the code in question. Can anyone help?

 

Thank you in advance!

 

AceOfJames

 

In this function after "The file was uploaded successfully!" I want to send the user to a different page. How would I accomplish that?

 

function stopUpload(success){

      var result = '';

      if (success == 1){

        result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';

      }

      else {

        result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';

      }

      document.getElementById('f1_upload_process').style.visibility = 'hidden';

      document.getElementById('f1_upload_form').innerHTML = result + '<label>File: <input name="myfile" type="file" size="30" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>';

      document.getElementById('f1_upload_form').style.visibility = 'visible';   

      return true; 

}

 

 

Link to comment
https://forums.phpfreaks.com/topic/142881-page-redirect-after-function-success/
Share on other sites

do you want any sort of delay in the redirect? if not, then you don't need that line:

 

function stopUpload(success){
      var result = '';
      if (success == 1){
//         result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
         window.location.href = 'page_to_go_to.html';
         return;
      }
      else {
         result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
      }
      document.getElementById('f1_upload_process').style.visibility = 'hidden';
      document.getElementById('f1_upload_form').innerHTML = result + '<label>File: <input name="myfile" type="file" size="30" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>';
      document.getElementById('f1_upload_form').style.visibility = 'visible';     
      return true;   
}

 

edit: for the delay:

function stopUpload(success){
      var result = '';
      if (success == 1){
         result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
         window.setTimeout("window.location.href = 'page_to_go_to.html'",1500); //Redirect after 1.5 seconds
      }
      else {
         result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
      }
      document.getElementById('f1_upload_process').style.visibility = 'hidden';
      document.getElementById('f1_upload_form').innerHTML = result + '<label>File: <input name="myfile" type="file" size="30" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>';
      document.getElementById('f1_upload_form').style.visibility = 'visible';     
      return true;   
}

 

edit again: had the code in the wrong spot

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.