首先,我没有制作此代码,我不是java程序员,我只是将其从“反馈表单”页面修改为“请求表单”页面。我的目标是禁用提交按钮并提醒用户,如果未选中该复选框,则需要勾选复选框和/或阻止其提交数据。我想尽可能避免使用javascript。
以下是代码片段:
public Serializable getKey() {
String email = parameters.getParameter("email", "");
String message = parameters.getParameter("message", "");
String page = parameters.getParameter("page", "unknown");
return HashUtil.hash(email + "-" + message + "-" + page);
}
/**
* Generate the cache validity object.
*/
public SourceValidity getValidity() {
return NOPValidity.SHARED_INSTANCE;
}
public void addPageMeta(PageMeta pageMeta) throws SAXException,
WingException, SQLException, IOException,
AuthorizeException {
pageMeta.addMetadata("title").addContent(T_title);
pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
pageMeta.addTrail().addContent(T_trail);
}
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException {
// Build the item viewer division.
Division ill = body.addInteractiveDivision("ill-form",
contextPath + "/ill", Division.METHOD_POST, "primary");
ill.setHead(T_head);
ill.addPara(T_para1);
List form = ill.addList("form", List.TYPE_FORM);
Text email = form.addItem().addText("email");
email.setAutofocus("autofocus");
email.setLabel(T_email);
email.setHelp(T_email_help);
email.setValue(parameters.getParameter("email", ""));
TextArea message = form.addItem().addTextArea("message");
message.setLabel(T_message);
message.setValue(parameters.getParameter("message", ""));
CheckBox copyright = form.addItem().addCheckBox("accept");
String selected = !parameters.getParameter("accept", "true").equalsIgnoreCase("false") ? "true" : "false";
copyright.setOptionSelected(selected);
copyright.addOption("accept", T_copyright_agree);
copyright.setLabel(T_copyright_label);
copyright.setHelp(T_copyright);
form.addItem().addButton("submit").setValue(T_submit);
ill.addHidden("page").setValue(parameters.getParameter("page", "unknown"));
}
}
提前感谢您的帮助。
答案 0 :(得分:0)
您可以将已定义复选框的HTML更改为: -
onClick="EnableSubmit(this)"
类似的东西: -
<input type="checkbox" name="ABC" value="XYZ" onClick="EnableSubmit(this)">