document.getElementById 질문 있습니다.
본문
//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
<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>
아이디를 다르게 하세요
name 값은 같지만 id 값은 다르게
jquery로 하면 더 편할텐데..
jquery를 사용 안하시는것 같아서..
<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>
답변을 작성하시기 전에 로그인 해주세요.