- Home
- Forum
- ASP.NET Core - EJ 2
- ejs-chiplist selected value pass in OnChage Event
ejs-chiplist selected value pass in OnChage Event
I am using syncfusion for displaying the list of subjects.
<ejs-chiplist id="chip-SubjectTags" selection="Single" click="FilterSubject" cssClass="e-primary">
<e-chips>
@foreach (var mySubject in (List<FilterSubjectInfo>)ViewBag.FilterTags)
{
<e-chip text="@mySubject.Name" value="@mySubject.SubjectTagID" enabled="true"></e-chip>
}
</e-chips>
</ejs-chiplist>
When selecting the subject let's say MATHS OR SCIENCE it calls the function FilterSubject(e) and fetch the data.
Now I have one dropdown list in which I have a list of Teacher's names.
<select class="form-control" id="selectTeacher" onchange="getTeacherVideo(this)">
</select>
function getTeacherVideo(selectObject) {
var value = selectObject.value;
//var abcValue = document.getElementById('chip-SubjectTags').selectObject;
//console.log(abcValue);
console.log(value);
}Here in getTeacherVideo() function I want to use the chip-SubjectTags, selected chip value.
How can I access chip-SubjectTags chip value in Javascript.
Greetings from Syncfusion support.
index.cshtml
|
<ejs-chiplist id="chip-avatar" click="FilterSubject" selection="Single" enableDelete="true">
<e-chips>
. . . </e-chips>
</ejs-chiplist>
<select name="cars" id="cars" onchange="getTeacherVideo(this)">
<script>
function getTeacherVideo(selectObject) {
var chip = document.getElementsByClassName('e-chip-list')[0].ej2_instances[0];//Chip instance.
var selected = chip.getSelectedChips(); //to get the value of the selected chip
console.log(selected);
}
</script> |
Please find the below sample for your reference
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Chip-893663432324703742.zip
Kindly check the following links to know more about Chip component.
Regards,
Shalini M.
Thank you for your reply, but in ONE PAGE I HAVE THREE LIST.
How can I identify on which chip list I am working on?
<ejs-chiplist id="chip-StudentTags" selection="Single" click="FilterClasses" cssClass="e-primary">
<e-chips>
</e-chips>
</ejs-chiplist>
<ejs-chiplist id=" chip-TeachersTags" selection="Single" click="TeacherFilters">
<e-chips>
</e-chips>
</ejs-chiplist>
<ejs-chiplist id=" chip-DepartmentTags" selection="Single" click=" DepartmentFilters">
<e-chips>
</e-chips>
</ejs-chiplist>
Good day to you.
|
<ejs-chiplist id="chip-StudentTags" click="findChipList" selection="Single" enableDelete="true">
<e-chips>
. . .
</e-chips>
</ejs-chiplist>
<ejs-chiplist id="chip-TeachersTags" selection="Single" click="findChipList">
<e-chips>
. . .
</e-chips>
</ejs-chiplist>
<ejs-chiplist id="chip-DepartmentTags" selection="Single" click="findChipList">
. . .
</ejs-chiplist>
<script>
function findChipList(args) {
var chip = document.getElementById(this.element.id).ej2_instances[0];//you can get the selected chip instance here]
alert("You have clicked the ' "+this.element.id+" ' ChipList")
}
</script> |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Chip-8936634321175489174.zip
API Link: https://ej2.syncfusion.com/documentation/api/chips/chipList/#click
Regards,
Shalini M.
Thank you for your help BUT. I am facing another issue here in the code which you have specified
console.log(selected);
if (chip.selectedChips.length == 0) {
var FilterTagInfo = {};
FilterTagInfo.FilterTagID = "";
FilterTagInfo.Name = "";
}
The problem is: -
If no chip is selected then I want to pass the ID AND NAME AS NULL but it shows me the error as shown down below.
Uncaught TypeError: Cannot read properties of null (reading 'length')
We checked your query and would like to let you know that the selectedChips property returns the selected chips Id. So we suggest you to check the selected items length using null value as demonstrated in the below code snippet.
|
function getTeacherVideo(selectObject) {
var chip = document.getElementsByClassName('e-chip-list')[0].ej2_instances[0];
var selected = chip.getSelectedChips();
console.log(selected);
if (chip.selectedChips == null) {
var FilterTagInfo = {};
FilterTagInfo.FilterTagID = "";
FilterTagInfo.Name = "";
}
} |
Please get back to us if you need further assistance.
Regards,
- 5 Replies
- 2 Participants
- Marked answer
-
HP Harshida Parmar
- Aug 27, 2021 01:46 PM UTC
- Sep 9, 2021 11:33 AM UTC