0
**Page <input type="text" id="page#" value={{Page_id}} style="width:50px; display:inline-block" > out of {{total}}
<input type="button" class="btn btn-outline-success" onclick="getDirection()" value="Go" style="display:inline">
<script>
   function getDirection(){
   var input = document.getElementById("page#").value;
   var new_id ="http://159.203.172.178/page/{{current_page.id_tei}}" ;
   new_id = new_id.slice(0,-3);
   new_id = new_id+input;
   console.log(new_id);
   window.location=new_id;
   }

** Hello, I am new to javascript. I am trying to make my django application take input from users and turn to the page based on their input. Right now, it works when I click on the button "Go". Is there a way I can make it work when I hit Enter key as well? I tried to use EventListener, but it tells me EvetListener is not a function. Great thanks.

S.Xia
  • 35
  • 5
  • Looks like someone already answered this one before https://stackoverflow.com/questions/155188/trigger-a-button-click-with-javascript-on-the-enter-key-in-a-text-box – Marcel Dumont Jun 22 '18 at 16:41
  • Possible duplicate of [Trigger a button click with JavaScript on the Enter key in a text box](https://stackoverflow.com/questions/155188/trigger-a-button-click-with-javascript-on-the-enter-key-in-a-text-box) – mhodges Jun 22 '18 at 16:45

1 Answers1

1

You can make it a form and have the function be called 'onSubmit'.

Nick V.
  • 121
  • 2