I need to match the value of multiple textareas to the properties of an object. It should only be a match if :
- the value of the
textareabeing used is equal to the person's name contained in the object and - if the index of the textarea is equal to the person's ID. (Cf boolean in my fiddle : https://jsfiddle.net/Lau1989/hxcpstty/1/)
To do this I need to access the object test = {} from this function :
function make_test(name, job, ID) {
var test = {}; //local variable to be used in 'function suggest(index)'
test.name = name;
test.job = job;
test.ID = ID;
return test;
}
new make_test("Paul", "manager", 1);
new make_test("John", "employee", 2);
new make_test("Jan", "employee", 2);
Inside this one :
function suggest(index) {
if (test.ID === index && test.name == thisInput.value) {
thisOutput.innerHTML = "Has job : " + test.job; //should access 'test' properties : test.name, test.job, test.ID
}
}
Problem is that declaring test = {}; as a global variable will only allow function suggest(index) to find 'Jan' because it is the last one I declared. But if I declare var test = {}; as a local variable it won't work at all because function suggest(index) can't access var test = {}; from outside.
This is where I'm stuck. My goal is to access var test = {}; within suggest() to get every person's job depending on their name and ID.
Thanks for your help
newwhen calling the function. So:var employees = []; employees.push(make_test(...));.suggestfunction stackoverflow.com/questions/39968429/…