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 trialSonja Tomcic
6,590 Pointsheeeeeeelp
i've tried but nothing passes
//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
<!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
Özgür Ozan Çakmak
11,451 PointsI'd like to give a more verbose answer:
//Show Prompt Window and store value
var fullName = prompt("What is your full name?");
//Select Input with the id of #fullName
var $fullNameInput = $("#fullName");
//Insert value in to full name input
$fullNameInput.val(fullName);
The code does the same thing exactly john larson posted.
First, you "catch" the data user has passed to you and assign it to
fullName
variable.Then you select the input with the id
fullName
by traversing the dom and selecting it via jquery. (this can be done bydocument.getElementById("fullName")
which incidentally how we did it back in the old prehistoric ages)and finally you pass the
fullName
variable to the input'sval
ue. (I especially like jQuery's approach regarding functions. If you pass a a parameter it turns into a setter (set this value), if not it turns into a getter (get this value))
john larson
16,594 PointsThis seemed to work
//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);
Sonja Tomcic
6,590 Pointsthanks a lot!!!!!!!!!!!!!
john larson
16,594 Pointsjohn larson
16,594 PointsOzgur, you obviously know the ins and outs. You must be doing Treehouse for kicks and giggles :D I'll be looking for more answers from you!
Özgür Ozan Çakmak
11,451 PointsÖzgür Ozan Çakmak
11,451 PointsThank you mate. I am only trying to stay up to date hehe.