Question: I have a very simple question. I have form input that I need to take in, and then redirect the browser based on that form input. I want to do it on the client side as the server is rather encumbered as it is. Here is my code, I have no clue why it's not working though. Any help is appreciated.

HTML:

```
<form action="open" method="" >
    <input type="number" name="space" id="redir" placeholder="e.g. '32'"/>
    <input type="submit" value="open" onclick="javascript:SubmitFrm()" class="radius button" style="font-family: Pacifico; font-size:2em">
</form>

```

Javascript:

```
function SubmitFrm(){
    console.log("function!")
    var space = document.getElementById("redir").value;
    console.log(space);
    window.location = "https://www.google.com/" + space; //for example.
}

```

Answer: 
You can use `onsubmit` in form to cancel redirecting action.

```
<form action="open" method="" onsubmit="SubmitFrm(); return false;">

```

Returning `false` in submit event will cancel default action, which is redirecting to form's `action`.
If you use `onsubmit` event, you don't need to put `onclick` event in submit button anymore.

So you can change your code to

```
<form action="open" method="" onsubmit="SubmitFrm(); return false;">
    <input type="number" name="space" id="redir" placeholder="e.g. '32'"/>
    <input type="submit" value="open" class="radius button" style="font-family: Pacifico; font-size:2em">
</form>
<script type="text/javascript">
    function SubmitFrm(){
        console.log("function!")
        var space = document.getElementById("redir").value;
        console.log(space);
        window.location = "https://www.google.com/" + space; //for example.
    }
</script>

```
Try to use a normal button instead of a form-submit, since a form submission will actually do a redirect to the given action itself. I'm not sure if your scriptcode is even fully processed before you are redirected to "open" action. Actually you don't even need a regular form for this.

Edit: What you could also do is setting the form method to "get" and modify the action to the destination prior to submitting the form. You could give your form an id for this and call formelement.submit(), because in this case a real submit button could also be a problem and a normal button would be probably better for this.