css - JavaScript Search Bar that Scrolls to input ID -


i'm new javascript, , i'm still learning speak.

i'm trying create search bar when user types in item name (ex. item 5) search bar scrollto item based off input , div's tag. site i'm working on long list of items, , clients know looking for.

i've seen lot of examples of how make button scroll div, not on how set input in search bar scroll div.

the scrolling method nice if smooth. based off of number value of input in. if it's string example "10.01a paper" i'd convert 1001a", , div named. <div id=1001a> make sense?

any advice great!

here demo

<form id="searchbox" action=""> <input id="search" type="text" placeholder="type here"> <input id="submit" type="submit" value="search"> 

item 1 item 2 item 3 item 4
.space {     width:100%;     height:500px;     background-color:#fff; } 

here's want, have fun it. https://jsfiddle.net/gkehnkdk/2/

the animation in lines:

$('html,body').animate({     scrolltop: $(this).offset().top }); 

i've made have enter "id" of item you're searching. can change code checking text of it. that's now.

in opinion easiest , simplest solution, , it's smooth too.

edit request user

to remove dots string, add

mystring.replace(/\./g, ""); 

after string.

working fiddle: https://jsfiddle.net/gkehnkdk/6/


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -