Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect to mypage.com#?test=1 using html forms + javascript?

I have page which handle dynamically some data. I want to redirect to that page from some static pages using form with value of test field - I need to send parameters with #. How can I do it?

<form class="search-form" method="get" action="#?">
        <input type="text" name="test" />
</form>

This solution ofc doesn't work.

I want for example write "1" in my form and then I should be redirected to mypage.com#?test=1.

Is there any function which parse form to generate url so I could just redirect? Or to just get value from submitting button link without actually redirecting?

like image 914
RaV Avatar asked Jun 19 '26 11:06

RaV


1 Answers

Try this:

<!DOCTYPE html>
    <html>
    <head>
        <title></title>
    </head>
    <body>
        <form class="search-form" method="get" action="">
            <input type="text" id="testbox" name="test" />
            <input type="button" id="button" onclick="hello()" value="send">
        </form>
        <script type="text/javascript">
            function hello(){
                var current_url = location.protocol + '//' + location.host + location.pathname + "#";
                location.replace(current_url + "?test=" + document.getElementById('testbox').value);
            }
        </script>
    </body>
    </html>

Hope this is what you meant.

like image 134
P. Kumar Avatar answered Jun 22 '26 00:06

P. Kumar