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 Getting a value

i cannot figure this out

Take a look at the app.js and preview. The aim of this application is to show what the user types in to the input field and preview it in the H1 tag. Almost all the code is there, there's just one thing missing. Retrieving the value from the input. I forgot how to do it. Could you finish it for me? Thanks!

Please provide the code you entered that is incorrect so we can show you what is missing.

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

The aim of this application is to show what the user types in to the input field and preview it in the H1 tag.

Looking at the HTML, what the user types in is held in the input element with the id "title". This is captured by the jQuery variable $titleInput

The previewTimer runs the function updatePreview every 1000 milliseconds (1 sec). This updates the previewTitle with the value of titleValue.

Unfortunately, titleValue is not set to anything. It is only declared.

The solution is to set titleValue to the current value of the $titleInput:

function updatePreview(){  
  //Get the user's input
  var titleValue = $titleInput.val();   //<-- fixed this line
  //Set the user input as the preview title. 
  $previewTitle.text(titleValue);
}