"HTML 라디오 버튼"의 두 판 사이의 차이

잔글 (로봇: 자동으로 텍스트 교체 (-http://jmnote.com/jq/ +http://zetawiki.com/jq/))
잔글 (로봇: 자동으로 텍스트 교체 (-http://zetawiki.com/jq/ +http://zetawiki.com/ex/jquery/))
49번째 줄: 49번째 줄:
</script>
</script>
</source>
</source>
*예제: http://zetawiki.com/jq/radio_button.php
*예제: http://zetawiki.com/ex/jquery/radio_button.php


==PHP==
==PHP==

2015년 7월 15일 (수) 00:49 판

  다른 뜻에 대해서는 라디오 문서를 참조하십시오.
HTML radio tag, radio button
HTML radio 태그
HTML 라디오 버튼
HTML RADIO 버튼
라디오 버튼 선택 항목 값 보기

1 자바스크립트

<!DOCTYPE html>
<meta charset="utf-8" />
<title>라디오 버튼</title>
<input TYPE='radio' id='r1' name='fruit' value='apple' /><label for='r1'>사과</label>
<input TYPE='radio' id='r2' name='fruit' value='banana' /><label for='r2'>바나나</label>
<input TYPE='radio' id='r3' name='fruit' value='lemon' checked='checked' /><label for='r3'>레몬</label>
<input type='button' value='선택된 항목 확인' onclick='show_checked();'/>
<script>
function show_checked() {
	var obj = document.getElementsByName('fruit');
	var checked_index = -1;
	var checked_value = '';
	for( i=0; i<obj.length; i++) {
		if(obj[i].checked) {
			checked_index = i;
			checked_value = obj[i].value;
		}
	}
	alert( '선택된 항목 인덱스: '+checked_index+'\n선택된 항목 값: '+checked_value );
}
</script>

2 jQuery

<!DOCTYPE html>
<meta charset="utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<title>라디오 버튼</title>
<input TYPE='radio' id='r1' name='fruit' value='apple' /><label for='r1'>사과</label>
<input TYPE='radio' id='r2' name='fruit' value='banana' /><label for='r2'>바나나</label>
<input TYPE='radio' id='r3' name='fruit' value='lemon' checked='checked' /><label for='r3'>레몬</label>
<input type='button' value='선택된 항목 확인' onclick='show_checked();'/>
<script type="text/javascript">
function show_checked() {
	alert('선택된 항목 인덱스: '+$("input[name='fruit']:checked").index("input[name='fruit']")
		+'\n선택된 항목 값: '+$("input[name='fruit']:checked").val());
}
</script>

3 PHP

radio_button.php
<!DOCTYPE html>
<meta charset="utf-8" />
<title>라디오 버튼</title>
<form method='post' action='radio_button_ok.php'>
<input TYPE='radio' id='r1' name='fruit' value='apple' /><label for='r1'>사과</label>
<input TYPE='radio' id='r2' name='fruit' value='banana' /><label for='r2'>바나나</label>
<input TYPE='radio' id='r3' name='fruit' value='lemon' checked='checked' /><label for='r3'>레몬</label>
<input type='submit' value='제출' />
</form>
radio_button_ok.php
<?php
echo '<xmp>';
print_r($_POST);
echo '</xmp>';
?>
실행결과
Array
(
    [fruit] => banana
)

4 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}