-1

After a user submits a form, they are redirected to a page with this url:

example.com?name=John

How can I put 'John' into a div on the page, so that the page displays 'Thank you John' ?

tlrichman
  • 33
  • 1
  • 6
  • 2
    based on the tags in your question, you can't use html to do that. you will need php or jquery for that. PHP: `echo "Thank you " . $_POST['name'];` or jquery (a whole lot more code) – Mech Sep 22 '20 at 01:57
  • https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript – epascarello Sep 22 '20 at 02:24
  • Unfortunately, I will need to use javascript/jquery for this situation. – tlrichman Sep 23 '20 at 04:47

1 Answers1

1

I'm not sure if i did understand you correctly, but if i did, you could get the value from query string and then change the div content just using vanilla JS.

Like this:

const name = new URLSearchParams(window.location.search).get('name') ?? "John";
const greeting = document.getElementById("greeting")

if(typeof(name) !== 'undefined' && name !== null){
  greeting.innerHTML = `Thank you ${name}`
  greeting.style.visibility = "visible"
}
<html>
  <div id="greeting" style="visibility:hidden"></div>
</html>

Ignore the ?? John is to have something to show without an actual query string.

Hope this is what you are looking for.

Esteban
  • 146
  • 1
  • 6