2番目または3番目のオプションを選択したときにテキストボックスを表示するコンボボックスは1つありますが、特定のオプションがコンボから選択されたときに自動的にテキストボックスが表示される
$("#combo").change(function() {
$.getJSON('combo.jsp', {
comboname: this.value
}, function (data) {
if(data.isTrue){
$("#textbox").empty().append("<input type='text' id='text1'/>");// display an empty text box
}
else{
// how to clear that text box and hide it?
}
});
});
HTML
<select id="combo" name="comboname">
<option value="_"></option>// how to clear and hide the text box when this option is
selected?
<option value="somevalue">somename</option>// when this option is selected then it
displays an empty text box
<option value="somevalue1">somename1</option>when this option is selected then it also
displays the same empty text box
</select>
// in the following div, text box is being displayed
<div id="textbox">
// here text box is displayed when option 2nd or 3rd is selected from the above combo
</div>
サーバ側(combo.jsp)
JSONObject jsonObj= new JSONObject();
jsonObj.put("isTrue","true");
response.setContentType("application/json");
response.getWriter().write(jsonObj.toString());
データはコンテンツタイプに基づいてjsonオブジェクトにする必要がありますか? if文の上の返り値関数でconsole.log(data)を試してください。返り値が単なる文字列を返す場合は、オブジェクトのような応答にアクセスする前にjQuery.parseJSON(data)する必要があります。 –
@j_mcnallyここでmiが間違っています:http://stackoverflow.com/questions/9377544/returning-sum-from-server-side-by-json – Phillipa