chandler Posted January 30, 2012 Share Posted January 30, 2012 Hi, I am using this bit of code <script type="text/javascript"> $(document).ready(function() { $('#countdown').countdown({seconds: 10}) setTimeout(function() { window.location.href = "index.php"; }, 10000); }); </script> to reload the page after contact us form is submitted, here it will reload index.php, however I am running this script on more than one page how can I make it reload from current url? Also I would I include javascript: return null; to stop the page jumping to top once form is submitted...Many Thanks for you help Quote Link to comment https://forums.phpfreaks.com/topic/256039-help-with-windowlocationhref-pls/ Share on other sites More sharing options...
Adam Posted January 30, 2012 Share Posted January 30, 2012 You can just use the window.location.reload() method. If you do that, the browser *should* automatically jump back to the same part of the page after the reload. Quote Link to comment https://forums.phpfreaks.com/topic/256039-help-with-windowlocationhref-pls/#findComment-1312563 Share on other sites More sharing options...
chandler Posted January 30, 2012 Author Share Posted January 30, 2012 <script type="text/javascript"> $(document).ready(function() { $('#countdown').countdown({seconds: 10}) setTimeout(function() { window.location.reload() }, 10000); }); Like this? when I do this the form keeps submitting / resending </script> Quote Link to comment https://forums.phpfreaks.com/topic/256039-help-with-windowlocationhref-pls/#findComment-1312565 Share on other sites More sharing options...
Adam Posted January 30, 2012 Share Posted January 30, 2012 I don't fully understand what you're trying to do. Why do you want to reload the page after a form is submitted? Also why is there a count down? Quote Link to comment https://forums.phpfreaks.com/topic/256039-help-with-windowlocationhref-pls/#findComment-1312567 Share on other sites More sharing options...
chandler Posted January 30, 2012 Author Share Posted January 30, 2012 here is what im working on, try out the contact for and you will see http://testserver3.webatu.com/index.php Quote Link to comment https://forums.phpfreaks.com/topic/256039-help-with-windowlocationhref-pls/#findComment-1312570 Share on other sites More sharing options...
Adam Posted January 30, 2012 Share Posted January 30, 2012 I would advise against what you're trying to do. After the form has been submitted and the page has finished loading, I don't see any benefit in refreshing the page? Keep requests to a minimum. The way I would do it would be to just display a little confirmation message above the form, notifying the user their message was sent successfully. That's it. Having said that, if you really want to do it, I would add a callback event to the countdown. Looks like you can use "onExpiry", assuming I'm looking at the right countdown plug-in: $(document).ready(function() { $('#countdown').countdown({ seconds: 10, onExpiry: function() { window.location.reload(); } }) }); Quote Link to comment https://forums.phpfreaks.com/topic/256039-help-with-windowlocationhref-pls/#findComment-1312579 Share on other sites More sharing options...
chandler Posted January 30, 2012 Author Share Posted January 30, 2012 I copy and paste your code, but the form didn't load after submitting... Keep requests to a minimum. The way I would do it would be to just display a little confirmation message above the form, notifying the user their message was sent successfully. That's it Can you show me how you would do it...sorry but I'm rubbish with JavaScript. Quote Link to comment https://forums.phpfreaks.com/topic/256039-help-with-windowlocationhref-pls/#findComment-1312669 Share on other sites More sharing options...
Adam Posted January 30, 2012 Share Posted January 30, 2012 On successfully sending the message, I would redirect back to the same page with a simple flag in the URL: if ($message_sent) { header('Location: index.php?sent'); exit; } Then when displaying the contact form: <?php if (isset($_GET['sent'])): ?> <p class="success">Thank you, your message has been sent.</p> <?php endif; ?> <!-- Contact form here.. --> Quote Link to comment https://forums.phpfreaks.com/topic/256039-help-with-windowlocationhref-pls/#findComment-1312672 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.