Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get the value selected in the filter select in dojo. But when I try to fetch the value I get the below error.
Uncaught TypeError: Cannot read property 'value' of null

What I have tried:

This is my filter select :
var filteringSelect = new FilteringSelect({
id: "stateSelect",
name: "state",
value: "CA",
store: stateStore,
searchAttr: "name",
}, "stateSelect");
filteringSelect.placeAt(win.body()).startup();

And I want to print the value selected in filter select :
var optVal = dijit.byId("stateSelect").item.value;
console.log(optVal);
What should I do?
Posted
Updated 12-Nov-17 6:26am

1 solution

Quote:
Uncaught typeerror: cannot read property 'value' of null

This is a very common error which occurs, when trying to access the member of an object which is null.
Fix: Validate for null value before accessing the members, but you will have to check why it is null at the first place, make sure the DOM contains the element with the id stateSelect
var optVal = dijit.byId("stateSelect");
if( optVal != null && optVal.item != null ) // validate for null  
console.log(optVal.item.value);
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900