How get input text field from HTML into JavaScript and go to URL?
I'm building one WebPage where you type some word into the input field and the Java gets this string and check if this string is equal to another, if it is go to some URL.
My code is:
<input type="text" name="procura" id="procura" />
<script>
name = oForm.elements["name"].value;
if (name.equals("Advogados"))
{
window.location = "http://jornalexemplo.com.br/lista%20online/advogados.html"
//do something
};
</script>
Can you give me some lights?
Note, I've used the jquery library here in my example as it makes setting up the listeners to handle these events easier.
You're referencing
oForm
in your code, but I don't see that in your examples... so I would think that you will find this easier if you wrap the in a form tag, with a particular id (procura
)Then capture the result using the id of the input element (
procura_texto
), and jquery'sval()
method and prevent the form from being submitted using the methodpreventDefault()
:here's a jsfiddle for you to play with: http://jsfiddle.net/zwbRa/5/
Use window.location.href = "your url".