I need to check if the value of multiple textareas is equal to the property name
of this object :
function make_test(name, job, ID) {
test = {};
test.name = name;
test.job = job;
test.ID = ID;
return test;
}
new make_test("Paul", "manager", 1); //doesn't work
new make_test("John", "employee", 2); //doesn't work
new make_test("Jan", "employee", 2); //works
It should only be a match if the value
is equal to the name and if the index of the textarea is equal to the person's ID
. For instance if I type "Paul" in textarea1
, it should output paul's job : but it should not output it in textarea2
which should only output the job of persons having an ID
= 2.
Problem : my code only works for the last person declared (Jan in this example). It's like the other persons don't even exist in the object, except for the last one. How can I fix this ?
I'm sure the answer is pretty obvious but I can't figure out what I'm doing wrong.
Demo here : https://jsfiddle.net/Lau1989/hxcpstty/
Thanks for your help
See Question&Answers more detail:os