1

First of all I did not make this code and I am not a java programmer, I just modified this from a "feedback form" page into a "request form" page. My goal here is to disable the submit button and alert the user that it is required to tick the checkbox and/or prevent it from submitting data if the checkbox is unchecked. As much as possible, I want to avoid using javascript.

Here's a snippet of the code:

    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"));
}
}

Thanks in advance for the help.

euler
  • 1,401
  • 2
  • 18
  • 39
  • *"I want to avoid using javascript."* JS wold be my natural choice for this. Why avoid it? – Andrew Thompson Aug 11 '13 at 06:38
  • If you are not a java developer you should do this in [javascript](http://stackoverflow.com/questions/5458531/how-do-i-disable-a-submit-button-when-checkbox-is-uncheck?rq=1) – Khinsu Aug 11 '13 at 06:38
  • Which Execution environment we are talking about? – Khinsu Aug 11 '13 at 06:40
  • @AndrewThompson, if I will use JS, is there a no JS fallback? Or will the form still submit if checkbox unchecked and JS disabled? – euler Aug 11 '13 at 06:49
  • *"if I will use JS, is there a no JS fallback?"* No. Just enable it by default and `onLoad` disable it. If the user's browser is not using JS, their experience of browsing most internet sites (e.g. FaceBook or SO) will be quite diminished, and they will be used to it. – Andrew Thompson Aug 11 '13 at 06:54

1 Answers1

0

You can change your HTML where you have defined the check box to like this:-

onClick="EnableSubmit(this)"

Something like:-

<input type="checkbox" name="ABC" value="XYZ" onClick="EnableSubmit(this)">
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331