繁体   English   中英

不正确的隐藏表单字段值被提交给servlet

[英]Incorrect hidden form field value being submitted to servlet

我的jsp中有一个带有两个文本值“ Regular”和“ Irregular”的下拉列表。 我需要使用隐藏的表单字段将所选的下拉文本发送到servlet。 我正在执行以下操作:

function addFundTypeHiddenFormField() {

    var dropdown= document.getElementById("dropdown");
    var formReq = document.getElementById("formReq");

    var input = document.createElement('input');

    input.id = 'fundingType';
    input.type = 'hidden';
    input.name = "fundingType"; 
    input.value = fundType.options[fundType.selectedIndex].text;
    console.log("dropdown: "+dropdown.options[dropdown.selectedIndex].text);
    formReq.appendChild(input);
}

下拉菜单中的默认选项是“常规”。 如果我将其更改为“ Irregular”并提交表单,则Servlet会收到值“ Irregular”。 但是,如果我将下拉列表更改为“ Irregular”,然后再次还原为“ Regualr”并提交表单,则servlet对于“ fundingType”仍然会获得“ Irregular”。 console.log会打印正确的值,作为我为下拉列表所做的任何选择。 我在这里不知所措..我该怎么做才能将正确的隐藏输入值发送到servlet?

添加以下代码有助于

 if(document.getElementById("fundingType")==null){
        console.log("input doesn't exist");
    }
    else{
        console.log("input exists");
        formReq.removeChild(document.getElementById("fundingType"));
    }

暂无
暂无

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

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