Computer >> 컴퓨터 >  >> 프로그램 작성 >> HTML

HTML DOM 입력 라디오 양식 속성

<시간/>

HTML DOM 입력 라디오 양식 속성은 지정된 입력 라디오 버튼이 포함된 양식 참조를 반환하는 데 사용됩니다. 라디오 버튼이 양식 외부에 있으면 단순히 NULL을 반환합니다. 이 속성은 읽기 전용입니다.

구문

다음은 입력 라디오 양식 속성의 구문입니다 -

radioObject.form

예시

입력 라디오 양식 속성의 예를 살펴보겠습니다.

<!DOCTYPE html>
<html>
<body>
<h1>Input radio form Property</h1>
<form id="FORM1">
FRUIT:
<input type="radio" name="fruits" id="Mango">Mango
</form>
<p>Get the form id by clicking on the below button</p>
<button type="button" onclick="formId()">GET FORM</button>
<p id="Sample"></p>
<script>
   function formId() {
      var P=document.getElementById("Mango").form.id;
      document.getElementById("Sample").innerHTML = "The id of the form containing the radio
      button is: "+P ;
   }
</script>
</body>
</html>

출력

이것은 다음과 같은 출력을 생성합니다 -

HTML DOM 입력 라디오 양식 속성

GET FORM 버튼 클릭 시 -

HTML DOM 입력 라디오 양식 속성

위의 예에서 -

먼저 type=”radio”, name=”fruits”, id=”Mango”인 양식 안에 입력 요소를 만들었습니다. 양식의 id 속성 값이 "FORM1"로 설정되어 있습니다. -

<form id=”FORM1”>
FRUIT:
<input type="radio" name="fruits" id="Mango">Mango
</form>

그런 다음 사용자가 클릭할 때 formId() 메서드를 실행하는 GET FORM 버튼을 만들었습니다. -

<button type="button" onclick="formId()">GET FORM</button>

formId() 메서드는 getElementById() 메서드를 사용하여 라디오 유형의 입력 필드를 가져오고 라디오 버튼이 포함된 양식 개체의 id 속성을 가져옵니다. 그런 다음 이 값을 변수 P에 할당하고 innerHTML 속성 -

을 사용하여 id가 "Sample"인 단락에 표시합니다.
function formId() {
   var P=document.getElementById("Mango").form.id;
   document.getElementById("Sample").innerHTML = "The id of the form containing the password field is: "+P ;
}