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

JavaScript jQuery Basics (2014) Creating a Mobile Drop Down Menu Setting a value

Julie Kohler
Julie Kohler
6,122 Points

Point of Setting a Value

Hey guys, can someone explain to me the purpose for setting a value this way? Under what circumstances would we use this method?

I'm also a little unclear on what is meant by Input here... :P

Hope these questions make sense. Thanks!

1 Answer

In this case the input refers to the input field in the index.html which has the id of "fullName".

<input id="fullName" name="fullName" value="" disabled>

what the task wants you to do is to set a value for this input field. In this case it will be the value inserted in the prompt so you have to set the input value equal to the promt that is stored in the variable "fullName" like this

$('#fullName').val(fullName);

There are lots of reasons why you would want to get a value from a prompt. You may want to print the results to your page for example. Or maybe you have a story game and every user input will be added to the story.

Julie Kohler
Julie Kohler
6,122 Points

Thanks for the help, but I'm still not sure I understand the difference between this and what we did in previous JS courses, where we might have written something like

var answer = prompt("Give an answer")

Is it that using jQuery methods allows us to affect our html?