-2

I have a form on my contract form, which submits to a third party site and then I can define a URL to return the user to. I currently return the user to the same /contact page but I wanted to give them a message that it had submitted (since ajax forms don't work with the third party) and I don't want to have a whole page for it.

Therefore I had the idea to return the user to /contact#thanks

I have some code on my site which goes like this:

<div id="alert" class="hidden">Form Submitted. We will reply soon.</div>

Now I want a small bit of javascript on my page which detects if the URL has the #thanks tag on it, as above, and then removes the hidden class from my alert div. Is javascript able to detect this and if so, how do I go about it?

Jimmy
  • 12,087
  • 28
  • 102
  • 192
  • 2
    Possible duplicate of [How can you check for a #hash in a URL using JavaScript?](http://stackoverflow.com/questions/298503/how-can-you-check-for-a-hash-in-a-url-using-javascript) – JJJ Feb 13 '16 at 13:20
  • Check the location api : https://developer.mozilla.org/en-US/docs/Web/API/Location –  Feb 13 '16 at 13:22

2 Answers2

1

Include jquery and script. I test and work

$(document).ready(function(){
  if(window.location.hash) {
   $("#alert").show()
  } 
});

Siii = Yes use hash Use hash

No hash

Maxi Schvindt
  • 1,432
  • 1
  • 11
  • 20
0

I'm not totally sure that I've understood what are you trying to achieve, but this might help you:

if (window.location.hash === '#thanks') {
    document.getElementById('alert').classList.remove('hidden');
}