Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript jQuery Basics (2014) Creating a Mobile Drop Down Menu Getting a value

Sági János
PLUS
Sági János
Courses Plus Student 6,185 Points

I dont understand

Hi Please send a solution i cant figure it out how to fix it. Thanks all

js/app.js
//Select the input for the title for blog post.
var $titleInput = $("#title");

//Select the preview h1 tag
var $previewTitle = $("#titlePreview");

// Every second update the preview
var previewTimer = setInterval(updatePreview, 1000);

function updatePreview(){  
  //Get the user's input
  var titleValue;
  //Set the user input as the preview title. 
  $previewTitle.text(titleValue);
}
index.html
<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="theme.css">
</head>
<body>
  <div id="form">
    <label for="title">Blog Post Title</label><input id="title" name="title" value="" placeholder="Enter your blog title here">
  </div>
  <div id="preview">
    <h1 id="titlePreview"></h1>
  </div>
  <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>
theme.css
  #form {
    width: 45%;
    float: left;
  }
  #preview {
    width: 45%;
    float: right;
  }
  label {
    width: 20%;
    display: inline-block;
  }
  input {
    width: 70%;
  }

2 Answers

Ryan Dudley
Ryan Dudley
Treehouse Project Reviewer

Sorry for the late reply, but hopefully I can be of some help and get you on your way!

In order to solve this code challenge you need to retrieve the value from the input field ($titleInput) and store the value within the titleValue variable. The value then gets passed into the $previewTitle.text(titleValue) method call.

So, in order to retrieve the value from our input with jQuery we can utilize the val() method on our $titleInput variable. So we would change the updatePreview() function like so:

function updatePreview(){  
  //Get the user's input -- This is where we can use the val() method to get the input's value
  var titleValue = $titleInput.val();
  //Set the user input as the preview title. 
  $previewTitle.text(titleValue);
}

I hope this was able to solve your issue, and if you have any additional questions don't hesitate to ask!

Steven Parker
Steven Parker
221,840 Points

Within an hour isn't "late". 3 days might be "late". :smile:

Sági János
PLUS
Sági János
Courses Plus Student 6,185 Points

Oh no problem! Thank you Ryan It's work finally. Great! Thanks everthing again. Okay I"ll dont be.