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

Sonja Tomcic
Sonja Tomcic
6,590 Points

heeeeeeelp

i've tried but nothing passes

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>

2 Answers

Özgür Ozan Çakmak
Özgür Ozan Çakmak
11,451 Points

I'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 by document.getElementById("fullName") which incidentally how we did it back in the old prehistoric ages)

  • and finally you pass the fullName variable to the input's value. (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))

Ozgur, 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
Özgür Ozan Çakmak
11,451 Points

Thank you mate. I am only trying to stay up to date hehe.

This 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
Sonja Tomcic
6,590 Points

thanks a lot!!!!!!!!!!!!!