Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

liam mcinnes
PLUS
liam mcinnes
Courses Plus Student 3,517 Points

Required element

Hey, I'm pretty new to html css and php, I'm making a website at the moment and im wanting to make a page for when the user first Vists the page it has a tet box that says "name" and saves the name. So on other pages it can be like "welcome (user name).

Is there any treehouse videos that shows this? Or can somone lead me that way :) thank you very much!

3 Answers

anil rahman
anil rahman
7,786 Points

If it was a box so you would give that box an id lets say "box" for now.

var value = document.getElementById("box").value;

so this is the same as i said before it gets an element by it's id in this case the "box" and by adding .value at the end it's saying find my box and get the value typed in and then put it all in my new variable called value.

Now you have the name they type in this value variable.

anil rahman
anil rahman
7,786 Points

JavaScript

var name = prompt("Please enter your name"); //store what is typed in name variable 

//then later on whereever you want to display this name just add this

document.getElementById("demo").innerHTML ="Hello " + person";

//remember where it says "demo" in getElement part you want to change it to the id of your     div or p tag or h1 tag or w.e.
liam mcinnes
PLUS
liam mcinnes
Courses Plus Student 3,517 Points

Thankyou but instead of the prompt, is there a way to add when they type it in a text box on the screen like the form element. Thank yku