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 trialeli d
Courses Plus Student 2,510 Pointsconcatenate not working . value variables = document.getElementById("new-var") - require expert help
Hey people I have to concatenate a list of value variables as in following example <script> var nameInput = document.getElementById("new-name"); var emailInput = document.getElementById("new-email"); var noInput = document.getElementById("new-number"); var zipInput = document.getElementById("new-zip");
var resultInput = nameInput + " " + emailInput + " " + noInput + " " + zipInput ;
// [object HTMLInputElement] [object HTMLInputElement] null [object HTMLInputElement]
// it should not be null (should carry value)
var resultInput = nameInput.concat(emailInput);
//Uncaught TypeError: nameInput.concat is not a function(anonymous function) @ app.js:10
</script>
please help
8 Answers
Byron Stine
4,877 PointsI have been working on your code. It was rough for me to figure out the delete part, but I figured it out. I did a for loop for adding the input values to the list. Check out my code on jsfiddle: (http://jsfiddle.net/r8n05d80/)
YI LI
4,094 PointsHi Eli concat() can be used for string and array. Your nameInput and emailInput are formatted in object. I think it is why your code doesn't work.
hope it helps.
eli d
Courses Plus Student 2,510 Pointsyes of course ... it have somebody any idea what can i do to concatenate these objects ?
Zoltán Holik
3,401 Points var nameInput = document.getElementById("new-name").value;
var emailInput = document.getElementById("new-email").value;
var noInput = document.getElementById("new-number").value;
var zipInput = document.getElementById("new-zip").value;
var resultInput = nameInput + " " + emailInput + " " + noInput + " " + zipInput ;
eli d
Courses Plus Student 2,510 Points// [object HTMLInputElement] [object HTMLInputElement] null [object HTMLInputElement]
eli d
Courses Plus Student 2,510 PointsTHATS NOT WORKING . IT THROWS ME // [object HTMLInputElement] [object HTMLInputElement] null [object HTMLInputElement]
Byron Stine
4,877 PointsThe reason you are getting the results [object HTMLInputElement] when you return the value of your variables is because your are only accessing the ID of the element. You have to access the innerHTML of that ID. This is done using .innerHTML at the end of your getElementById() method. Example:
var nameInput = document.getElementById("new-name").innerHTML;
var emailInput = document.getElementById("new-email").innerHTML;
var noInput = document.getElementById("new-number").innerHTML;
var zipInput = document.getElementById("new-zip").innerHTML;
var resultInput = nameInput + " " + emailInput + " " + noInput + " " + zipInput ;
eli d
Courses Plus Student 2,510 PointsByron Olson-Stine could you help me with the folowing code in js please ? http://jsfiddle.net/u27Lytqt/
its the whole script there . Right now I can add only one variable to the list instead 4 . Thanks in advance . Trying a lot to solve the problem by myself
eli d
Courses Plus Student 2,510 PointsByron Olson-Stine could you help me with the folowing code in js please ? http://jsfiddle.net/u27Lytqt/
its the whole script there . Right now I can add only one variable to the list instead 4 . Thanks in advance . Trying a lot to solve the problem by myself but it doesn t work
Byron Stine
4,877 PointsI'm looking over the code and it has to do with this code:
if(taskInput.value) {
cTasksHolder.appendChild(listItem);
bindTaskEvents(listItem);
} else {
alert("You must enter the name , the email , the phone and the zip code.");
}
Toward the top of you javaScript code you have this:
var nameInput = document.getElementById("new-name");
...
var taskInput = nameInput;
Notice you have the if statement comparing the taskInput.value which you have assigned as the variable that holds the nameInput variable that holds the single object ID="new-name". Since this is a single item it's only adding a single item to the list. I would put your input objects into an array and then incorporating a for loop around your if statement that cycles through the array to add them to the list. With more time I can come up with some example code. But hopefully this will get you in the right direction.
eli d
Courses Plus Student 2,510 Pointsi modified the array . http://jsfiddle.net/u27Lytqt/1/ still need help or some directions if that's possible. Thanks you very much
eli d
Courses Plus Student 2,510 PointsI ve changed var taskInput ¬javascript¬¬ var taskInput = [nameInput , emailInput , noInput, zipInput];
it seems that I have now to grab each element and output and i m wondering a bit how cause I have var createNewTaskElement = function(taskString) { ...... label.innerText = taskString; ... }
eli d
Courses Plus Student 2,510 Pointseli d
Courses Plus Student 2,510 Pointsthanks you ... now i need to validate inputs in javascript as text , mail , phone no and number. Asloo i need to add a popup each time i add / delete a line of code . wish me good luck causei need it . thx you again