Appending form input value to action url as path

后端 未结 2 596
梦毁少年i
梦毁少年i 2020-11-30 10:26

I have a form like this:

相关标签:
2条回答
  • 2020-11-30 11:09

    You can use onsubmit and use jQuery to obtain the same result.

    Check the following.

    HTML Code:

    <form id = "your_form" onsubmit="yourFunction()">
        <input type="text" name="keywords">
        <input type="submit" value="Search">
    </form>
    

    jQuery Code:

        function yourFunction(){
    
        var action_src = $("keywords").val();
        var your_form = $('your_form').val();
    
        var urlLink = "http://localhost/test/";
        urlLink = urlLink + action_src;
    
    
    
        your_form.action = urlLink;
    
    }
    
    0 讨论(0)
  • 2020-11-30 11:12

    You can use onsubmit attribute and set the action inside a function for example:

    <form id = "your_form" onsubmit="yourFunction()">
        <input type="text" name="keywords">
        <input type="submit" value="Search">
    </form>
    
    function yourFunction(){
        var action_src = "http://localhost/test/" + document.getElementsByName("keywords")[0].value;
        var your_form = document.getElementById('your_form');
        your_form.action = action_src ;
    }
    
    0 讨论(0)
提交回复
热议问题