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

Adam maitland
PLUS
Adam maitland
Courses Plus Student 211 Points

.value problem

Hello here is my code

<!DOCTYPE html> <html> <head>

<title></title> <link rel="stylesheet" href="stylesheet.css">

</head>

    <body>

        <div class="wrapper">

            <form>

             <label name="name">Your Name:</label>
     <input type="user_name" name="user_name" id="user_name">
             <label name="email">Your Email:</label>
             <input type="text" name="email" id="email">
             <label name="message">Your Message:</label>
             <textarea name="message" id="message">


             </textarea>
     <input id="button" type="submit" value="send">



            <p id="test"></p>

        </div>

<script src="validate.js"></script>

    </body>

</html>

here is the javaScript

<script>

function get() {

var user_name = document.getElementById("user_name"); console.log(user_name.value);

}

get();

</script>

for some reason the value of the name input isn't updating ??

3 Answers

Adam, when you say:

var user_name = document.getElementById("user_name");

you are getting the entire element, not just the contents. It may work better to get the inputted text first, and then log that. So I suggest you try:

var user_name = document.getElementById("user_name").value;

and then log that. Hope this helps.

Adam maitland
Adam maitland
Courses Plus Student 211 Points

Thanks for your reply Jcorum but its still coming back as empty

P.S., didn't notice the first time through, but it's label for:

<label for="name">Your Name:</label>

That shouldn't affect the Javascript, but it will affect your html.

Can you send the URL for the challenge? I've tried to set it up in my dev environment, but I don't have a console, etc., and so it would be a lot easier if I could test changes in the correct workspace.