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 trialthomas halse
1,804 PointsA prompt dialog will open prompting for someone's full name. Use jQuery to follow the comments in code. First, select th
Does anyone know what to do here?
//Show Prompt Window and store value
var fullName = prompt("What is your full name?");
//Select Input with the id of #fullName
$select
//Insert value in to full name input
<!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>
4 Answers
geoffrey
28,736 PointsHere is the way to achieve it.
//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
$('#fullName').val(fullName);
/* $('#fullName') -> selects the input with this id.
.val() -> JQuery method to get a value from an element or set the value if a value is passed.
In this case, we set the value of the input to the value we get from the prompt.
*/
Tanner Marshall
13,717 PointsHey Thomas!
It looks like you'll want to use first use JQuery to select the <input> with id="fullName", like this:
$('#fullName')
Which selects the input field with id = 'fullName', then you'll want to add whatever gets typed into the fullName variable from the prompt to the empty value attribute of the input field, i.e. where it says value below:
<input id="fullName" name="fullName" value="" disabled>
To do that, you can use JQuery's attr(), where you first put the attribute that you want to change (the HTML attribute value) and then then what you want to change it to (the JS variable fullName):
$('#fullName').attr('value', fullName);
And that should do it! Now whatever gets stored in the fullName variable from the prompt should show up in the input field!
Hope that helps!
Waldo Alvarado
16,322 PointsHere is a "strict" interpretation of solving this problem:
(1) the first comment simply says to select the input (tag) with the id fullName, which means to get a reference for it and store it in a variable.
(2) it then tells you to add the value of the prompt into the the above fullName input. PS: This problem is unnecessarily vague in what it wants you to do.
Solution:
//Show Prompt Window and store value
var fullName = prompt("What is your full name?");
//Select Input with the id of #fullName
var refInput = $("#fullName");
//Insert value in to full name input
refInput.val(fullName);
Charles Franklin
17,535 PointsI have a question about the logic here.. If what we wanted to get from the user was going to be used as a tag in an HTML document, why wouldn't we have asked for that in the first place?
var #fullName = prompt("What is your full name?");
Now we have what the user typed in stored in a variable #fullName that can be called by the HTML and inserted as necessary.. ??