AceOfJames Posted January 29, 2009 Share Posted January 29, 2009 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; } Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 29, 2009 Share Posted January 29, 2009 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 Quote Link to comment Share on other sites More sharing options...
AceOfJames Posted January 29, 2009 Author Share Posted January 29, 2009 Hi Aaron, Thanks! That worked perfectly! What if I just wanted the page to refresh itself instead? How would that work? AceOfJames Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 29, 2009 Share Posted January 29, 2009 window.location.reload(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.