I have a form and I want to retrieve it's URL after the Submit button is clicked.
What I've done so far is to Submit the <form> through JavaScript .submit() method , then store the URL using window.location.search into a variable and then I also alert() it.
When I fill the form for the first time, the alert doesn't show anything and when I fill it for the second time it returns the values that I filled the first time.
Note: I need to stay on the same page after clicking the Submit button.
Edit: The alert happens first and then the form gets submitted and the variables are appended to the URL.
Here is my code for reference:
<html>
    <body>
        <div>
            <h1>Form 1</h1>
            <form id="form1" method="GET">
                Number 1:<input type="text" id="num1" name="num1">
                <br>
                Number 2:<input type="text" id="num2" name="num2">
                <br>
                Number 3:<input type="text" id="num3" name="num3">
                <br>
                Number 4:<input type="text" id="num4" name="num4">
                <br>
                <button id="sub1" onclick="submitFunc()">Submit</button>
            </form>
        </div>
        <script>
            function submitFunc()
            {
                document.getElementById("form1").submit();
                var loc = window.location.search;
                alert(loc);
            }
        </script>
    </body>
</html>
 
    