insertRow,insertCell,createElement,innerHTML
insertRow,insertCell,createElement,innerHTML 을 사용하시면 됩니다.
예제입니다.
<html>
<head>
<script>
function myAdd() {
var tab=document.all.mytable;
var row=tab.insertRow();
var col=row.insertCell();
var inp=document.createElement("input");
inp.type="text";
col.innerHTML=inp.outerHTML;
}
</script>
</head>
<body>
<input type=button value=add onclick=myAdd()>
<table id=mytable border=1></table>
</body>
</html>
답변 내용 추가
맞습니다.
inp.name="test";
형태로 하시면 됩니다.
name이 같게 여러개를 주면 배열로 보시고 null확인 등의 작업을 하시면 됩니다.
예)
if (typeof(document.formname.test.length)=="undefined") {
if (document.formname.test.value=="") {
alert("test값이 null입니다");
document.formname.test.focus();
}
} else {
for (var i=0; i<document.formname.test.length; i++) {
if (document.formname.test[i].value=="") {
alert((i+1)+"번째 test값이 null입니다");
document.formname.test[i].focus();
break; //혹은 함수면 return;
}
}
}
혹은 애초에 name속성에 일련번호등을 붙여 값을 다르게 주는 방법도 있겠습니다.<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]</div>
예제입니다.
<html>
<head>
<script>
function myAdd() {
var tab=document.all.mytable;
var row=tab.insertRow();
var col=row.insertCell();
var inp=document.createElement("input");
inp.type="text";
col.innerHTML=inp.outerHTML;
}
</script>
</head>
<body>
<input type=button value=add onclick=myAdd()>
<table id=mytable border=1></table>
</body>
</html>
답변 내용 추가
맞습니다.
inp.name="test";
형태로 하시면 됩니다.
name이 같게 여러개를 주면 배열로 보시고 null확인 등의 작업을 하시면 됩니다.
예)
if (typeof(document.formname.test.length)=="undefined") {
if (document.formname.test.value=="") {
alert("test값이 null입니다");
document.formname.test.focus();
}
} else {
for (var i=0; i<document.formname.test.length; i++) {
if (document.formname.test[i].value=="") {
alert((i+1)+"번째 test값이 null입니다");
document.formname.test[i].focus();
break; //혹은 함수면 return;
}
}
}
혹은 애초에 name속성에 일련번호등을 붙여 값을 다르게 주는 방법도 있겠습니다.<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]</div>
댓글 2개
19년 전
오!
19년 전
주제랑은 좀 틀린거 같은데.... ㅡㅡ^
name 값을 'test[]' 주고
document.getElementsByName('test[]') 로 접근하시길 권장한다고 하네요..? 누가? 음.......
ex)
var str_var = document.getElementsByName('test[]');
for(i=0;i<str_var.length;i++) {
alert(str_var[i].value);
}
name 값을 'test[]' 주고
document.getElementsByName('test[]') 로 접근하시길 권장한다고 하네요..? 누가? 음.......
ex)
var str_var = document.getElementsByName('test[]');
for(i=0;i<str_var.length;i++) {
alert(str_var[i].value);
}
게시글 목록
| 번호 | 제목 |
|---|---|
| 8374 | |
| 28446 |
HTML
리눅스 압축관련 명령어
|
| 8373 |
JavaScript
퍼미션관련 명령어
|
| 8371 |
MySQL
MySQL 덤프방법(dump)
1
|
| 8370 |
MySQL
여러데이터베이스 사용하는 방법
|
| 8364 |
기타
PHP 기초 테크닉
5
|
| 29219 | |
| 28444 |
HTML
연산자(Operators)
1
|
| 28443 |
HTML
PHP 제어구조
|
| 8359 |
기타
주요메타테그 모음
4
|
| 8357 |
MySQL
백업&복구(전체/부분/테이블)
1
|
| 8356 | |
| 8355 | |
| 8354 |
MySQL
리눅스 기본 명령어 모음[펌]
|
| 8350 |
JavaScript
dhtml menu (pull down, top down 방식 메뉴)
3
|
| 8347 | |
| 8342 | |
| 8339 | |
| 8336 |
JavaScript
체크박스를 이미지로...
2
|
| 8335 |
기타
리눅스의 디렉토리 구성
|
| 8332 | |
| 8331 | |
| 8330 |
MySQL
MySQL root 패스워드 분실했을 경우
|
| 8323 | |
| 8314 |
JavaScript
PHP 홈페이지
8
|
| 8307 | |
| 8302 |
Linux
리눅스 배포판 선택하기
4
|
| 8297 | |
| 8293 | |
| 8281 |
JavaScript
우편번호를 이용한 소재지 셀렉트 박스
11
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기