html 라디오 버튼 제어
jQuery 단.
$(document).ready(function(){
$('input[type=radio][name=이름]').change(function(){
// 함수 호출.
fn_radio_call();
});
});
// 함수...
function fn_radio_call(){
var test_val = $(":input:radio[name=이름]:checked").val();
$.ajax({
type: "POST",
url: "${pageContext.request.contextPath}/testService",
data: {"test_val":test_val},
dataType: 'json',
success: function (data) {
if (data.result > 0) {
location.reload();
}
else {
alert("에러가 발생했습니다.\n잠시후 다시 시도해 주세요.");
}
},
error: function (e) {
alert("에러가 발생했습니다.\n잠시후 다시 시도해 주세요.");
}
});
}
HTML 단.
<td>
<span><input type="radio" name="이름" id="radio_이름_1" value="Y" <c:if test="${vo.test_val == 'Y'}">checked</c:if>>Yes</span>
<span><input type="radio" name="이름" id="radio_이름_2" value="N" <c:if test="${vo.test_val == 'N'}">checked</c:if>>No</span>
</td>
Java 단.
@RequestMapping(value = "/testService", method = RequestMethod.POST)
public String test(HttpSession session,
@RequestParam(value = "test_val", defaultValue = "") String testVal, Model model) {
try {
} catch (Exception e) {
}
return "jsonView";
}