Jump to content

help with window.location.href... pls


chandler

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/256039-help-with-windowlocationhref-pls/
Share on other sites

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

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();
        }
    })
});

 

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.

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

 

 

 

 

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.