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
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

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.