Nick Harwy Nick Harwy - 6 months ago 12
HTML Question

How to go through the link in html?

I have a little question. in my html page i have a text box, where i can type

anything i want
. When i press ENTER i want to go through the next url
http://127.0.0.1:8000/search/?request=anythingiwant
Is there eny methods to do this in html code?? Here the code



{% extends 'finder/base.html' %}
{% block content %}
<div class="container">
<div class="image"></div>
<h2>Super Search Engine</h2>
<p>I'm searching for:</h2>
<input type="text" id="inp" onkeypress="return runScript(event)">
</div>

<script>
function runScript(e) {
if (e.keyCode == 13) {
//var tb = document.getElementById("scriptBox");
//eval(tb.value);
//return false;
alert("kekos");
$.ajax({
method: 'POST',
url: 'http://127.0.0.1:8000/search/',
data: {
'request': document.getElementById('inp').value,
},
success: function(data){
$scope.key = data['key'];
$scope.isAuthorized = true;
$window.alert('You are logged in.');
},
error: function(data){
$window.alert("Something was wrong.");
},
})
}
}
</script>
{% endblock content %}




Answer

If you want to reload from the new URL, assign to window.location instead of sending an AJAX request.

if (e.keyCode == 13) {
    window.location = "http://127.0.0.1:8000:/search/?" + encodeURIComponent(event.target.value);
}