Friday, 23 August 2013

jQuery: Loop through multiple inputs and save answer to variable

jQuery: Loop through multiple inputs and save answer to variable

So far, I have:
$('.the-inputs input').each(function() {
userAnswer = $(this).val();
});
However, if I console.log this out, it comes out on separate lines (is
this an array?) I would like it as a string.
So, if the user enters "Hello" "World" in the two inputs, I want the
variable userAnswer = "Hello World".
I also need the var accessible outside the function. Am I right in leaving
off the var to achieve this?
Thanks!

No comments:

Post a Comment