so I have an empty web page, with a button and a Label, when the button is clicked the label is filled with data from my database. I am new to asp.net, so I would like to know is there any way I can add a search box in the page, that I can search for data that is displayed in the Label.
Example: I have list of cities in the Label and I want to see where is the city LONDON.
I will provide some images:
A way to change style of a html element using javascript would be the following:
<input type="text" id="SearchBox" onInput="OnSearchTextDidChange()">
<ul>
<li id="London">London</li>
<li id="Paris">Paris</li>
<li id="Sweden">Sweden</li>
<li id="Europe">Europe</li>
</ul>
<script>
htmlIds = ["London", "Paris", "Sweden", "Europe"];
function OnSearchTextDidChange(){
var text = document.getElementById("SearchBox").value.toString();
for(var i = 0; i < htmlIds.length;i++){
if(htmlIds[i] == text){
document.getElementById(htmlIds[i]).style.color = "yellow";
}
else{
document.getElementById(htmlIds[i]).style.color = "black";
}
}
}
</script>
Be aware that this solution is case-sensitive
make a an html input element, and handle the input from user with javascript:
<input type="text" onInput="OnSearchTextDidChange()">
<script>
function OnSearchTextDidChange(){
//do what you want when search text changes
}
</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.