简体   繁体   English

chnage表单操作onchange()选项已提交并提交了不起作用的相同表单

[英]chnage form action onchange() option filed and submit the same form not working

I have a form where I have a dropdown selection box. 我有一个表格,其中有一个下拉选择框。 My requirement is when the user changes the option from the select box then the form action should change accordingly and the form should be submitted automatically. 我的要求是,当用户从选择框中更改选项时,表单操作应相应更改,并且表单应自动提交。 I have the following code in my form section: 我的表单部分中包含以下代码:

<form id="topicSelectionFormId" action="${headerLink.topicUrl}" method="GET">
    <select id="topic-option-id" class="dd-custome-new" onchange="changeTopic(this)">
        <c:forEach items="${headerLink.topicList}" var="topic">
            <option value="${topic.menuItemId}" ${topic.menuItemId == headerLink.topicId ? 'selected' : ''}>${topic.name}</option>
        </c:forEach>
    </select>
</form>

And then I have the javascript code to handle the form action change part as: 然后,我有javascript代码来处理表单操作更改部分,如下所示:

<script>
function changeTopic(sel){
    var topicId = sel.value;
    var formAction = $('#topicSelectionFormId').prop('action') + topicId;
    alert(formAction);
    $("#topicSelectionFormId").attr("action", formAction);
    $("#topicSelectionFormId").submit();
}
</script>

The alert is showing the correct required form action I need. 警报显示我需要的正确的所需表单操作。 But the form is not submitted to the desired url. 但是表单未提交到所需的URL。 Can anybody help on this? 有人可以帮忙吗?

  function changeTopic(sel){ var topicId = sel.value; document.topicSelectionFormId.action = topicId; document.topicSelectionFormId.submit(); } 
  <form name="topicSelectionFormId" action="action-default" method="GET"> <select id="sss" onchange="changeTopic(this);"> <option value="action1">action1</option> <option value="action2">action2</option> </select> </form> 

your code is perfectly working in my IE11 browser. 您的代码在我的IE11浏览器中运行正常。 In browser's developer tools, check in network , whether your request is going to desired url and what response you are receiving. 在浏览器的开发人员工具中,检查network,您的请求是否将到达所需的URL以及收到的响应是什么。

This is not my answer, But I don't have enough reputations to comment under your question, so writing here 这不是我的答案,但是我的声誉不足,无法在您的问题下发表评论,因此请在此处写

我认为您需要在操作中设置为所需的网址。不是formAction

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM