JAVASCRTIP 버튼을 통한 라디오 & 체크박스 & 셀렉박스 선택

[JAVASCRTIP] 버튼을 통한 라디오 & 체크박스 & 셀렉박스 선택

<form name=TEST_FORM>
<input type='radio' name=radio_name value=1>
<input type='radio' name=radio_name value=2>
<input type='radio' name=radio_name value=3>
<input type='checkbox' name=checkbox_name value=0>
<input type='checkbox' name=checkbox_name value=1>

<select name='select_name'>
<option value='0'>-- 선택 --</option>
<option value='1'>-- 1 --</option>
<option value='2'>-- 2 --</option>
<option value='3'>-- 3 --</option>
</select>

</form>

<input type=button value='test button 1' onclick='test_action1()'>
<input type=button value='test button 2' onclick='test_action2()'>

<script>
function test_action1()
{
 document.getElementsByName('radio_name')[1].checked=true;
 document.getElementsByName('checkbox_name')[1].checked=true;
}

function test_action2()
{
 F = document.TEST_FORM ;
 F.select_name.selectedIndex = 2;
}
</script>
라디오버튼 변경하기 아래 참조

$("input:radio[name='fruits']:radio[value='사과']").prop('checked', true); // 선택하기
$("input:radio[name='fruits']:radio[value='사과']").prop('checked', false); // 해제하기

- 본문 -
<label><input type="radio" name="fruits" value="사과">사과</label>
<label><input type="radio" name="fruits" value="복숭아">복숭아</label>

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다