폼객체란 일반적인 폼에 접근할 때 사용한다. 폼객체는 id 또는 name을 이용하여 접근한다. 또한 id, name 말고 documents.forms 컬렉션을 이용하여 접근할 수도 있다.
const f = document.myform;
-> name은 .을 사용하는 것이므로 이는 name으로 접근 하였다.
const f = document.getElementById('regform);
-> 요거는 id로 접근한 것이다.
const id = document.myform.userid.value;
const id = frm.userid.value;
const id = frm.elements[0].value;
const id = frm.elements['userid'].value;
const id = document.getElementById('id').value;
-> id value로 접근방법이 여러가지가 있다. 이 5가지 방법 모두 사용할 수 있다.
form을 활용한 코드이다.
<form name = "myform" id="reform" method="post" action="regist.php">
아이디: <input type = "text" name="userid" id="id"><br>
비밀번호:<input type = "password" name="userpw" id="pw"><br>
<input type="submit" value="전송">
</form>
이렇게 form을 사용할때 아이디나 비밀번호를 post 방식으로 설정하고 전송을 눌렀을 때 type을 sumbit로 하여 아이디와 비밀번호를 제출할 수 있게 만든다.
아이디:그러면 이런식으로 결과가 나온다.