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

canΒ΄t store fullname value to input....

I just cant get it working....

js/app.js
//Show Prompt Window and store value
var fullName = prompt("What is your full name?");

//Select Input with the id of #fullName
var $name = $("#fullName");
//Insert value in to full name input
fullName.val($name.attr("value"));
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

Hello Renanto!

Looks like you are trying to access a jQuery method on a native JavaScript object fullName.

Try talking the problem out first.

  • You get the full name from the js prompt and you store that in fullName.
  • You get the jQuery object $('#fullName') and store that in $name
  • Now using the jQuery object that you stored, $name, access the .val() method on that variable.
  • Finally pass the name that was stored, fullName, into the .val() method to put it into the input field.

The last line of code will look like this:

$name.val(fullName);

Thank you very much for the answer.

But i still wasn-t able to figure this one out. I have tried storing on the variable $name the input location with the attribute value, but I am getting the following error:

Bummer! There was an error with your code: TypeError: 'undefined' is not a function (evaluating '$name.val(fullName)')

HERE IS MY CODE:

//Show Prompt Window and store value var fullName = prompt("What is your full name?");

//Select Input with the id of #fullName var $name = $("#fullName").attr("value"); //Insert value in to full name input $name.val(fullName);

In this little demo there are three steps and you had steps 1 and 2 right. Step 3 is where the issue is not step 2 and 3.

So following my guide:

// get fullName
var fullName = prompt("What is your full name?");

// get jQuery object
var $name = $("#fullName");

//set the value of the input field use the .val() method of $name by passing fullName as the argument
$name.val(fullName);

Perfect. Now i got it! I was trying to go more specific. Thanks!!!!!!!