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 trialkhoipro
10,821 PointsA 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,
//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()
});
<!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
Luke Pettway
16,593 PointsThe 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);
khoipro
10,821 PointsHi,
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?
Luke Pettway
16,593 PointsExcellent 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?
khoipro
10,821 PointsThank you for your explain.