Question about Dynamically adding html modules and submitting forms in jsp: jsp forms
Several questions about Dynamically adding html modules and submitting forms in jsp.
Corresponding project: market
Module: PesticideCheck
Case: Add sampling sub-objects dynamically (multiple Entity combinations)
Solution: Use the DOM model flexibly
function addItem(obj) { itemId++; var item = $(obj).parent().parent().next(); var group = item.find("p")[0]; item.append($(group).html()); var temp = item[item.length - 1]; var groupOther = item.find("p")[itemId]; var radioObjY = $(temp).find("input")[0]; var radioObjN = $(temp).find("input")[1]; if (item!=1) { $(radioObjY).attr("name", "screeningResult" + itemId); $(radioObjN).attr("name", "screeningResult" + itemId); } } function removeItem(obj) { var pSum = document.getElementById("items").getElementsByTagName("p").length; if (pSum != 11) { $(obj).parent().parent().parent().remove(); } else { return; } }
At the same time, the corresponding select needs to dynamically Add the onchange event, you can use
Onchange = "getCommodityBatchByCommodity (this. value, this)" solves the problem. Find the select
You can use the same name attribute for form submission and submit objects and data in the form submission controller method, for example:
public String savePesticideCheck(@Valid @ModelAttribute("pesticideCheck") PesticideCheck pesticideCheck, BindingResult result, @RequestParam("shopId") int[] shopId, @RequestParam("batchId") int[] batchId,@RequestParam("commodityId") int[] commodityId, ModelMap modelMap)