채택완료

document.getElementById 질문 있습니다.

2015-12-28 (월) 10:42:34 2,426
Copy
//html <input type="radio" id="aaa" name="aaa" value="상시모집" onclick="enddaychk(this);">상시모집<input type="radio" id="aaa" name="aaa" value="채용시까지" onclick="enddaychk(this);">채용시<input type="radio" name="aaa" value='' onclick="enddaychkfalse();">   자바스크립트 var eee =document.getElementById("aaa").value;

같은 id값인 radio 체크가 3개 있는데요 3개중 체크 된값만

 

자바스크립트 getElementById 할시 불러오고 싶습니다.

 

체크된것만 불러오고 싶다는 건데요.

 

이런경우 어떻게 해야되는지 ㅠ,ㅠ

|

답변 3개

채택된 답변
+20 포인트

<input type="radio" name="aaa" value="상시모집" onclick="enddaychk();">상시모집
<input type="radio" name="aaa" value="채용시까지" onclick="enddaychk();">채용시
<input type="radio" name="aaa" value='' onclick="enddaychk();">

<script type=text/javascript>

function enddaychk() {
 var eee = document.getElementsByName("aaa");


 for(var i=0; i< eee.length; i++) {
  if(eee[i].checked) {
   alert(eee[i].value);
  }
 }
}
</script> 

jquery로 하면 더 편할텐데..

jquery를 사용 안하시는것 같아서..

Copy
<input type="radio" name="aaa" value="상시모집">상시모집<input type="radio" name="aaa" value="채용시까지">채용시<input type="radio" name="aaa" value=''><input type="button" value="체크항목 확인" onclick="get_value();"> <script> function get_value(f) {var select_value="";var is_checked = document.all.aaa.length;  for (i=0;i<is_checked ;i++)  {   if (document.all.aaa[i].checked == true)  select_value+=document.all.aaa[i].value;}if(select_value) alert("체크된 항목은 "+select_value+" 입니다");} </script>

아이디를 다르게 하세요

name 값은 같지만 id 값은 다르게

답변을 작성하려면 로그인이 필요합니다.