Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Archives
Today
Total
관리 메뉴

자기 혐오 개발자

html 라디오 버튼 제어 본문

Javascript,jQuery

html 라디오 버튼 제어

올라치노 2018. 5. 25. 15:58


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

}