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 trialJoshua Steffan
Front End Web Development Techdegree Student 9,010 PointsCreating a mobile drop down menu - Getting a Value
Hi Everyone, I'm just a bit lost here and Im struggling to see what I'm doing wrong. Am I on the right path?
//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; $titleInput.val();
//Set the user input as the preview title.
$previewTitle.text(titleValue);
}
<!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>
#form {
width: 45%;
float: left;
}
#preview {
width: 45%;
float: right;
}
label {
width: 20%;
display: inline-block;
}
input {
width: 70%;
}
1 Answer
Nate Conley
16,191 PointsJust change:
var titleValue; $titleInput.val();
to:
var titleValue = $titleInput.val();
Joshua Steffan
Front End Web Development Techdegree Student 9,010 PointsJoshua Steffan
Front End Web Development Techdegree Student 9,010 PointsOh man that is really embarrassing! Thanks for the second set of eyes! I think I need to slow down a bit and watch my keys!