Jump to content
Fórum Script Brasil
  • 0

Duvida de iniciante - Javascript de busca


tpiardi

Question

A minha idéia é fazer um textbox que você irá digitar algo e ele adicionará isso ao final da url que abrirá em uma nova janela.

Exemplo:

Url: http://www.warofninja.com/profile/

Box: teste

Pagina aberta: http://www.warofninja.com/profile/teste

No entanto meu código está fazendo algo errado, alguém pode me dizer o que é o problema?

Obrigado

var elmSearchDiv = document.createElement('div');
    elmSearchDiv.innerHTML =
        '<form method="GET" action="http://www.warofninja.com/profile/">' +
        '<label for="player">Digite o nome:</label> ' + 
        '<input type="text" id="player"> ' + 
        '<input type="submit" value="Search">' +
        '</form>';
    document.body.insertBefore(elmSearchDiv, document.body.firstChild);
    elmSearchDiv.style.fontSize = 'small';
    elmSearchDiv.style.textAlign = 'right';
    elmSearchDiv.style.borderBottom = '1px solid silver';

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Tenta esse ai:

HTML

<form>
<label>
<span>http://www.warofninja.com/profile/</span>
<input type="text" />
</label>
<input type="submit" />
</form>
e JavaScript
window.onload = function(){
document.getElementsByTagName('form')[0].onsubmit = function(){
location.href = 'http://www.warofninja.com/profile/'+this.getElementsByTagName('input')[0].value;
}
}

Edited by vini_loock
Link to comment
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
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  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.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...