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

A prompt dialog will open prompting for someone's full name and display it on input.

Hi,

I can not understand how to complete this challenge.

Show prompt window to ask Full Name, then display it on input id #fullName.

Thank you,

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

//Select Input with the id of #fullName
  $("#fullName").select(function() {
//Insert value in to full name input
    $value = $("#fullName").attr("value");
    $(value).text()
  });
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>

2 Answers

The way this challenge is worded is a little weird and I'm not sure why it was made into two parts as that makes it even more confusing. Basically what it is asking you to do is use the jQuery selector method/function which is $() to select the input with the id of #fullName. So the first step is to select it like so $('#fullName').

Now that we have the selector ready, we can chance the value by using the .val() function. Since the prompt is what is getting us that info, and it is being assigned to the fullName variable, we can use the function like this .val(fullName), adding it to the $('#fullName') selector, which would look like this $('#fullName').val(fullName).

Here is what the final output would look like:

//Select Input with the id of #fullName
$('#fullName');
//Insert value in to full name input
$('#fullName').val(fullName);

Hi,

Thank you for answer. It makes me confused just because when filling an input with a value, should I care about attribute 'value=' and insert a result into this value?

Excellent question Nguyen.

.val() has two uses. If you don't supply anything in the method, it reads the value of the selected form element, however if you supply data it changes the value of that form element instead.

What this means is that if you pass in data such as a string or variable (fullName) inside of .val() you are setting the value of that element. For example $('#myInput').val('I Like Cats'); would set the value of the input myInput to the string 'I Like Cats'. Does that make sense?

Thank you for your explain.