0

I have a Jsp file that include these lines:

<s:select list="list" name="message" id="selectMsg"></s:select>
<div id="txtMessage" style="display:none">
   <h3>
      <span id="txtMessage" style="margin-left: 230px">
          Message: <s:textarea name="message" placeholder="Message"/>
      </span>
   </h3>
</div>

Action:

public String warn() throws Exception {
    WarnDAO dao = new WarnDAO();

    AccountDAO accdao = new AccountDAO();
    acc = accdao.getAccountByUsername(username);

    List<WarningMessage> warningMessage = dao.showMsg();
    list = new ArrayList<String>();
    for (WarningMessage warningMessage1 : warningMessage) {
        list.add(warningMessage1.getMessage());
    }
    list.add("Other");


    warning_msg_DAO wmDAO = new warning_msg_DAO();
    wm = wmDAO.getByMessage(message);

    DateFormat dateFormat = new SimpleDateFormat("hh:mm a dd/MM/yyyy");
    Date date = new Date();
    System.out.println(dateFormat.format(date));
    WarningAccount warningAcc = new WarningAccount();
    warningAcc.setWarnedaccount(acc);
    warningAcc.setMessage(message);
    warningAcc.setDay(date);

    dao.warn(warningAcc);
    return "success";
}

In the s:select include an option "Other". When the user choose "Other" the text area will display and allow user to input their own message. Is there any solution?

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • You are reinventing the wheel. The object you are looking for is most likely an [autocompleter](http://jqueryui.com/autocomplete/#combobox), unless you really need a textarea (eg. to preserve the line breaks) for your alternate text. In that case, just use vanilla javascript, or jQuery, or whatever, to show/hide the textarea based on the value of the select. – Andrea Ligios May 14 '15 at 15:49

1 Answers1

2

function toggleOther(val){
    document.getElementById("other").style.display = (val=="other") ? "block" : "none";
}
<select onchange="toggleOther(this.value);">
    <option value="foo"  >________ FOO ________</option>
    <option value="bar"  >________ BAR ________</option>
    <option value="other">_______ OTHER ______</option>
</select>
<div id="other" style="display: none;">    
    <textarea>I'm visible only when choosing OTHER</textarea>
</div>
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243