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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.