Topic: Accessing the search input box in javascript to manually filter/search
Bonanos pro asked 4 years ago
Hi all,
I'm trying to access the Search input on a datatable using javascript and manually set it depending on a users choice. I don't have any of my own inputs on the page so I tried to access it using (where it seems 'search' is set as a class name in the code)
document.getElementsByClassName("search")[0].value = 'my text here';
and also document.getElementsByTagName("input")[0].value = 'my text here';
but neither seem to work. Ideally I want to set the text in the input so the user can see instead of doing it behind the scenes and allow the datatable api to handle the filtering based on what is input in the existing search input.
Any suggestions would be greatly appreciated.
Cheers Shaun
Bonanos pro answered 4 years ago
Ok, sorted, for anyone insterested, to set the value of the search input on a datatable in javascript :
$('input[type="search"]').val('your search text here').keyup();
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Resolved
- ForumUser: Pro
- Premium support: No
- Technology: MDB jQuery
- MDB Version: 4.17.0
- Device: laptop
- Browser: chrome
- OS: windows 8
- Provided sample code: No
- Provided link: No