Dropdownlist get value out ddl and use it above

五迷三道 提交于 2019-12-11 19:16:55

问题


I'm trying to make a dropdownlist of the months. When the user select a month, the javascript fills the setter with the chosen value. Now I want to use that value above. So I made a form around my select with the action 'Onchange' and use the getMaand to calls the chosen month.

Is there something wrong with the form? Because when I put this in comment, I get the dropdownlist with the months, when I put it in code, he prints every month in one line.

I'm not an expert in Java, is it correct to use Onchange in the form and in the select?

    int m = -1;
    HTMLCode += "<form onchange=\"window.open('availability.jsp?user=99&clickeddate="+dateFormat.format(today.getTime())+"&month=" + avail.getMaand() + "','_self')\"";
    HTMLCode += "<select onchange='javascript:setMonth(\"" + m + "\");'>";
    for (m=today.get(Calendar.MONTH); m<12; m++){    
    if(month == m)
    HTMLCode += "<option value='" + m + "' selected>" + maand_voluit[m]+ "</option>";
    else
    HTMLCode += "<option value='" + m + "'>" + maand_voluit[m] + "</option>";
    }
    HTMLCode += "</select>";
    HTMLCode += "</form>";

Kind regards


回答1:


You don't specify a value for month

Try this:

int month = today.get(Calendar.MONTH);
HTMLCode += "<form onchange=\"window.open('availability.jsp?   user=99&clickeddate="+dateFormat.format(today.getTime())+"&month=" + avail.getMaand() + "','_self')\"";
HTMLCode += "<select onchange='javascript:setMonth(\"" + m + "\");'>";
for (int m=0; m<12; m++){    
if(month == m)
HTMLCode += "<option value='" + m + "' selected>" + maand_voluit[m]+ "</option>";
else
HTMLCode += "<option value='" + m + "'>" + maand_voluit[m] + "</option>";
}
HTMLCode += "</select>";
HTMLCode += "</form>";


来源:https://stackoverflow.com/questions/16010696/dropdownlist-get-value-out-ddl-and-use-it-above

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!