简体   繁体   中英

Javascript function not defined at onkeyup in my code

I have wrote a javascript function to search and filter elements But it says in console log that function not defined at onkeyup

THe Function should get text in search box check if this text is a substring of any of a string in div's inside container if its a substring then keep element as it is otherwise hide it Instead its not working and says function not definet at onkeyup

  function myfunction(){ var container, divwithtext , textinbox, textinboxincapital, boxsearch; container=document.getElementById("container"); divwithtext=container.getElementsByTagName("div"); boxsearch=container.getElementById("searchbox"); textinbox=boxsearch.value.toUpperCase(); console.log(textinbox); for(i=0 ; i<length.divwithtext; i++) { textindiv=divwithtext[i].textContent || divwithtext.innerText; if(textindiv.toUpperCase().indexOf(textinbox) > -1){ divwithtext[i].style.display=""; } else{ divwithtext[i].style.display="none"; } } } 
 <style> .container{ background-color:pink; width:60%; position:absolute; left:20%; } .imagebox{ width:13vw; height:35vh; background-color:green; display:inline-block; margin-left:7%; margin-bottom:5%; color:white; } .searchbox{ width:80%; height:50px; margin-bottom:1%; margin-top:1%; margin-left:7%; } </style> 
  <div class="container" id="container"> <input type="text" class="searchbox" placeholder="Search Here" onkeyup="myfuction()" id="searchbox" /><br> <div class="imagebox" name="box" style="background:url('adult-beach-casual-736716.jpg'); background-size:100% 100%; color:black;">PEXELS<br>Tim Savage</div> <div class="imagebox" name="box" style="background:url('attractive-beautiful-beauty-415829.jpg'); background-size:100% 100%;">PEXELS<br>PIXABAY Girl</div> <div class="imagebox" name="box" style="background:url('beautiful-beauty-blurred-background-1239291.jpg'); background-size:100% 100%;color:black; text-align:right;">PEXELS <br>Daniel Xavier</div> <div class="imagebox" name="box" style="background:url('adult-boy-casual-220453.jpg'); background-size:100% 100%;color:black;">PEXELS <br>PIXABAY Boy</div> <div class="imagebox" name="box" style="background:url('beautiful-brunette-cute-774909.jpg'); background-size:100% 100%; color:black;">PEXELS<br>Bruce Mars</div> <div class="imagebox" name="box" style="background:url('facial-hair-fine-looking-guy-614810.jpg'); background-size:100% 100%;">PEXELS<br>Simon Robben</div> </div> 

<input type="text" class="searchbox" placeholder="Search Here" onkeyup="myfuction()" id="searchbox" />

look closely at function name that is being called in onkeyup. It should be myfunction and not myfuction as pointed out by @ Devsi Odedra

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM