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

Alex Davis
Alex Davis
10,958 Points

Which videos should I review for help with this objective? Does it relate to the each() method?

I'm stuck on the objective where I have to select an "input" (<input> element?) and insert a value from another variable (can't look up which one right now, it's being blocked by this window, it's in the mobile drop down lesson). It doesn't feel like it uses the each() method we went over in the previous video, and I don't know what I'm supposed to be doing.

js/app.js
//Show Prompt Window and store value
var fullName = prompt("What is your full name?");

//Select Input with the id of #fullName

//Insert value in to full name input
index.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<label for="fullName">Full Name</label><input id="fullName" name="fullName" value="" disabled>
<script src="//code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/app.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>

3 Answers

Steven Parker
Steven Parker
229,745 Points

You are correct, each() is not needed here.

All you do for this challenge is set the value of an element. And you don't even need to refer to the HTML, since the comments tell you what the id of the element is. So if you know how to select an element using the id, and you know how to set the value of an element, you can actually do this challenge with one short line of code.

I'll bet you can get it now without an explicit spoiler.

Antonio De Rose
Antonio De Rose
20,884 Points

I show you both ways of doing, vanilla JS and JQuery

//Show Prompt Window and store value
var fullName = prompt("What is your full name?");

//Select Input with the id of #fullName
$("#fullName").val(fullName);//this is the only line you need to pass this challenge, continued from above.

//vanilla JS way, just for your reference
//document.getElementByID("fullName").value = fullName;

//Insert value in to full name input
Steven Parker
Steven Parker
229,745 Points

Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime. :fishing_pole_and_fish:
    ― Maimonides

Alex Davis
Alex Davis
10,958 Points

Thanks, both. I eventually figured it out. I was confused by the multiple lines of notes, causing me to think i had to break it up into 2 lines by storing in a variable or something.

Steven Parker
Steven Parker
229,745 Points

It can be done on 2 lines using an intermediate variable. But you can also do it on one line.