jquery - Javascript - How do I call the object? -


As you can see I have created three objects, each has a different array. Whitesmate = {option: ["chicken", "turkey"]}, fish = [variant = "options" ["beef", "steak", "kangaroo"]} {Option: ["salmon", "tuna"]};

Then, in HTML I have created a selection area with three similar options.

  & lt; Choose name = "meat-type" & gt; & Lt; Option value = "redmeat" & gt; Red flesh & lt; / Options & gt; & Lt; Option value = "whitet" & gt; White meat & lt; / Options & gt; & Lt; Option value = "fish" & gt; Fish & lt; / Options & gt; & Lt; / Select & gt;   

Now, whenever the user selects the field, I want to be able to display the right array in my console. (For example, when red meat is selected, then the console "beef", "steak", "kangaroo" will be logged.)

  $ ('select [name = meat - type] ') .change (function () {var e = $ ("select [name = meat-type] option: selected") Val (); function updatefield (e) {console.log (e); / / This works, easy .f = e.options; // But it does not work, returns the undefined console.log (f);}; updatefield (e);});   

So the question is; How do I call an object?

Firstly, you need to modify your object and put it into a single object.

After that you can easily call the object and get its value. ["Chicken", "turkey"], fish: ["salmon", "white", "meat", "meat", " Tuna "]}; $ ('Choose [name = meat-type]'). Change (function () {console.log (meatObj [this.value]);});

for the above code

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -