提交javascript表单但数据未正确传递

时间:2013-10-08 10:30:23

标签: javascript forms spring-mvc

我试图通过提交表单来传递值,但是当它提交时我看不到任何传递URL的数据。它得到了LOGGER的证实。

JavaScript代码

function validateSelectedCombination(){

var program_Id = document.getElementById('id_select_program').value;


alert(program_Id);
document.getElementById('id_select_program').value;
document.getElementById("programFormDropDown").action=("../hDashBoard/project");
document.getElementById("programFormDropDown").submit();

}

JSP文件中的

表单

<form id="programFormDropDown">
    <label>Program :</label>    
    <select id="id_select_program" class="selectpicker" data-live-search="true" title='Choose Program...'>            
          <c:forEach var="program" items="${programs}">
            <option  value="${program.programId}">${program.programName}</option>
        </c:forEach>            
    </select> 

    <input type="button" onclick="validateSelectedCombination()" value="Submit">        

控制器

@RequestMapping(value = "/project" , method = RequestMethod.GET)
public ModelAndView programValidate(HttpServletRequest request , ServletResponse response) throws Exception {

    String programId = request.getParameter("id_select_program");
    LOGGER.info("Selected program id" + programId);
    ModelAndView fileConfigModelView = new ModelAndView("fileUpload");
    return fileConfigModelView;
}

1 个答案:

答案 0 :(得分:0)

只能提交具有name属性的字段,将name属性添加到您的select中,如下所示: