0

I want to modify the URL query string before submitting the form. I'm having a form like below:

 <form name="sampleForm" id="sampleForm" method="get" action="/detailVal" style="display:inline">
            <input type="hidden" name="cId" value="${lId}"/>
            <input type="hidden" name="sId" value="${sId}"/>
            <input type="hidden" name="pKey" value="${pKey}"/>

    onclick="return resetPage('sampleForm',)"><img height="40" width="30" src="/img/next123.png"/></a>

    </form>

    <script type="text/javascript">
    function resetPage(formName) {
         var thisForm = doc
       }    
    </script>

Before submitting the form I want to change the URL from /detailVal?cId=1&sId=2&pKey=3 to /detailVal/cId/1/sId=2/pKey/

4

2 回答 2

0

url 的构建方式似乎没有任何逻辑,因此仅传递带有从元素中插入的值的字符串可能就是您想要做的,然后阻止表单提交并重定向到该 url :

<script type="text/javascript">
    function resetPage(formName) {
         var thisForm = doc
       }    

    $(function() {
        $('#sampleForm').on('submit', function(e) {
            e.preventDefault();
            var cId = $('[name="cId"]').val(),
                sId = $('[name="sId"]').val();

            window.location.href = '/detailval/cid/'+cid+'/sid='+sId+'/pKey/';
        });
    });
</script>
于 2013-07-17T10:49:15.510 回答
0

您可以尝试onsubmit功能。

于 2013-07-17T10:40:13.127 回答