Colocar Resposta 
 
Avaliação do Tópico:
  • 0 votos - 0 Média
  • 1
  • 2
  • 3
  • 4
  • 5
Javascript - replace what you write in a text box into a link
31-10-2011, 22:00
Mensagem: #1
Javascript - replace what you write in a text box into a link
In my site, I would like to have a text box where people could write a number and then from that number, a link was made, something like this:

If the user wrote 123 in the text box and clicked that button, which would open the link:

http://teste.com/Qualifier=123&Token =

or

If the user wrote 184 in the text box and clicked that button, which would open the link:

http://teste.com/Qualifier=184&Token =

______________________________

Is it possible? Which is the necessary code?
Procurar todas as mensagens deste utilizador
Citar esta mensagem numa resposta
01-11-2011, 19:42
Mensagem: #2
RE: Javascript - replace what you write in a text box into a link
It's simple...
You just need change the method for GET and put on the action attribute the relative url.

Like this:
<form name="..." method="GET" action="your url">

And automatically the browser, will put the variable on the url.

[Imagem: mLvbVUs.png]
Procurar todas as mensagens deste utilizador
Citar esta mensagem numa resposta
02-11-2011, 07:27 (Esta mensagem foi modificada pela última vez a: 02-11-2011 07:49 por dani1997.)
Mensagem: #3
RE: Javascript - replace what you write in a text box into a link
Eu pensava que o fórum era inglês. Podemos continuar em português.

Acontece que o link que contém a variável não é no meu site. E como eu disse, gostaria de ter uma caixa de texto, onde o utilizador escrevesse a variável e depois ao clicar num botão, fosse levado ao url com a variável aplicada. Acho que isso requer um pouco de javascript, não?
Procurar todas as mensagens deste utilizador
Citar esta mensagem numa resposta
02-11-2011, 16:11 (Esta mensagem foi modificada pela última vez a: 02-11-2011 16:12 por Mettafox.)
Mensagem: #4
RE: Javascript - replace what you write in a text box into a link
É assim, podes sempre ir pelo jQuery, e usar uma função.

A resolução será qualquer coisa como:

$('#id_form').bind("submit", function(){
var url="http://teste.com/Qualifier=" + $('#id_da_caixa_de_texto').val() + "&Token=";

$('#id_do_elemento_a_href').attr('href', 'url');
});

ou

<form ..... onsubmit="changeURL('this.nome_do_campo_text.value')">

var url="";
function changeURL(url){
windows.location="http://teste.com/Qualifier=" + url + "?Token=";
}


Experimenta e depois dá feedback.
Cumprimentos.

[Imagem: mLvbVUs.png]
Procurar todas as mensagens deste utilizador
Citar esta mensagem numa resposta
02-11-2011, 17:16 (Esta mensagem foi modificada pela última vez a: 02-11-2011 17:18 por dani1997.)
Mensagem: #5
RE: Javascript - replace what you write in a text box into a link
Código:
<script>
    
    var url="";
function changeURL(url){
windows.location="http://teste.com/Qualifier=" + url + "?Token=";
}
    </script>


<form onsubmit="changeURL(url)">
<input type="text"/>
<input type="submit" value="Submit" />
</form>

Assim continua a não funcionar. Tens alguma ideia do que está a falhar? Na tag form deveria ser:
Código:
<form onsubmit="changeURL(url)" action="...">
Mas eu não sei o que escrever na parte "action".
Procurar todas as mensagens deste utilizador
Citar esta mensagem numa resposta
03-11-2011, 00:26
Mensagem: #6
RE: Javascript - replace what you write in a text box into a link
No onsubmit, não podes pôr a variável url.

Tens de pôr como disse: onsubmit="changeURL('this.nome_do_input_text.value');"
No input text, tens de adicionar o name="qualquercoisa"

No action, podes deixar vazio ou então mete #.

[Imagem: mLvbVUs.png]
Procurar todas as mensagens deste utilizador
Citar esta mensagem numa resposta
15-11-2011, 23:01
Mensagem: #7
RE: Javascript - replace what you write in a text box into a link
Ok, thanks
Procurar todas as mensagens deste utilizador
Citar esta mensagem numa resposta
Colocar Resposta 


Saltar Fórum:


Utilizadores a ver este tópico: 1 Visitante(s)