Jump to content
N3lson

[Resolvido] Colocar valor em input[text]

Recommended Posts

N3lson

boa tarde, estou a iniciar-me em javascript, e pretendia realizar o seguinte.

exemplo:

ter um array serie

var serie = [2,8,9,99,93,60,62];

colocar num input quando um utilizador por exemplo mal clique no numero 9 apareça a sugestão dos valores existentes no array

9, 93, ou 99

Poderiam me ajudar?

Edited by N3lson

You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.

Share this post


Link to post
Share on other sites
HappyHippyHippo

tens alguma biblioteca de javascript preferencial ou vai em javascript normal ?


IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites
N3lson

Javascript normal


You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.

Share this post


Link to post
Share on other sites
HappyHippyHippo
<!DOCTYPE html>
<html>
   <head>
       <script>
           var serie = [2,8,9,99,93,60,62];

           function load() {
               var input = document.getElementById('input');
               var sugest = document.getElementById('sugest');
               input.onkeyup = function() {
                   sugest.innerHTML = '';
                   if (input.value != '') {
                       serie.forEach(function(elem) {
                           elem += '';
                           if (elem.search(input.value) != -1) {
                               sugest.innerHTML += elem + '<br />';
                           }
                       });
                   }
               }
           }
       </script>
   </head>
   <body onload="load();">
       <input id="input" />
       <div id="sugest"></div>
   </body>
</html>

Edited by HappyHippyHippo
  • Vote 1

IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites
N3lson

Obrigado.


You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.