I want to implement a search functionality in java script.I am new to java script.if i have committed any blunder in the code below forgive me.
How should I implement it?
I tried implementing like this
javascript
$("#input").keyup(function() {
var userInput = $(this).val();
$("#list div").map(function(index, value) {
$(value).toggle($(value).text().toLowerCase().indexOf(userInput) >= 0);
});
});
BUT,CORDOVA EITHER DOES NOT RECOGNIZE $...SO WHEN i IMPLEMENTED IT LIKE THIS
document.getElementById("input").keyup(function() {
var userInput = val();
document.getElementById("main div").map(function(index, value) {
document.getElementById(value).toggle(document.getElementById(value).text().toLowerCase().indexOf(userInput) >= 0);
NOW, I GET an error as
05-30 11:59:18.500: INFO/Web Console(930): JSCallback Error: TypeError: Result of expression 'document.getElementById("input").keyup' [undefined] is not a function. at file:///android_asset/www/cordova-2.1.0.js:3727
html
<input type="text" id="input"/>
<div id="list">
<div>Rich</div>
<div>Rajim</div>
<div>vimal</div>
<div>RAGHU</div>
</div>
Please,suggest me a solution to work on.
The problem is that you're not including JQuery. As soon as you include it, it works. jsfiddle here: http://jsfiddle.net/Y49EW/
$("#input").keyup(function () {
var userInput = $(this).val();
console.log("here");
$("#list div").map(function (index, value) {
$(value).toggle($(value).text().toLowerCase().indexOf(userInput) >= 0);
});
});
To include jQuery:
1) download jquery (choose a version) from here: http://jquery.com/download/
2) add this into the head
tag of your html page
<script type="text/javascript" src="jquery-versionyouchoosed.js"></script>
For example, if you are using 1.9.1 version, you need to use-
<script type="text/javascript" src="jquery-1.9.1.js"></script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.