R

자바스크립 고수님 들..ㅠ.ㅠ 도와주세요..

이런저런 이유로 요 몇일 스킨을 제작중인데요..ㅠ.ㅠ

스크립이...ㅜ.ㅜ 말을 안들어가...

innerHTML 로 테이블과 텍스트 박스 및 셀렉트 박스를 생성후
컨트롤 하려 하는데요.
이상하게 primary_key() 에서
var optionValue = document.create_table['create_field_name['+i+']'].value;
요넘을 못불러오네요..ㅠ.ㅠ

datetype()에서는
document.create_table["create_date_len["+j+"]"].value
요넘은 아주 잘 불러지고 있는데요..ㅠ.ㅠ
그런데 요넘두 primary_key() 요기로 가서 부르면 안오더라구요..ㅜ.ㅠ
뭘 잘못한건지 도저히 알수가없어서 자문을 구합니다..

아래는 소스 입니다.





<style>
.field_title {
height:30px;
color: #FFFFFF;
}
.field_text {
color: #333333;
}
</style>
<script>
var i = 0;
function add_field()
{
oRow0 = document.createElement('tr');
oRow1 = document.createElement('tr');
oCel0 = document.createElement('td');
oCel1 = document.createElement('td');
oCel2 = document.createElement('td');
oCel3 = document.createElement('td');
oCel4 = document.createElement('td');
oCel5 = document.createElement('td');

oRow0.style.textAlign='center';
oRow0.style.height='32';
oRow1.style.textAlign='center';
oCel5.height='1';
oCel5.bgColor='#e3dcd2';
oCel5.colSpan='5';

oCel0.className='cel0';
oCel1.className='cel1';
oCel2.className='cel2';
oCel3.className='cel3';
oCel4.className='cel4';
oCel5.className='cel5';

oRow1.appendChild(oCel5);
oRow0.appendChild(oCel0);
oRow0.appendChild(oCel1);
oRow0.appendChild(oCel2);
oRow0.appendChild(oCel3);
oRow0.appendChild(oCel4);
oRow0.appendChild(oRow1);

oCel0.innerHTML="#"+i;
oCel1.innerHTML="<input type='text' name='create_field_name["+i+"]' style='width:100%; background-color:#f6f6f6; border:1px solid #d8d8d5; height:21px;' itemname='테이블명' required>";
oCel2.innerHTML="<select name='create_date_type["+i+"]' onChange='datetype(this.value, "+i+")' style='width:100%; background-color:#f6f6f6; border:1px solid #d8d8d5; height:21px;' itemname='데이터 타입' required><option selected='selected'>DateType</option><option value='int'>INT</option><option value='char'>CHAR</option><option value='varchar'>VARCHAR</option><option value='text'>TEXT</option></select>";
oCel3.innerHTML="<input type='text' name='create_date_len["+i+"]' style='width:100%; background-color:#f6f6f6; border:1px solid #d8d8d5; height:21px;' itemname='문자길이'>";
oCel4.innerHTML="<select name='create_not_null["+i+"]' style='width:100%; background-color:#f6f6f6; border:1px solid #d8d8d5; height:21px;' itemname='NULL'><option value='n'>NOT NULL</option><option value='y' selected='selected'>NULL</option></select>";
oCel5.innerHTML="";

document.getElementById('table_field').children(0).appendChild(oRow0);
document.create_table.field_count.value=i;
i++;
}


function del_field()
{
var tbody = document.getElementById('table_field');

if(tbody.rows.length > 4) {
tbody.deleteRow(tbody.rows.length-2);
i--;
document.create_table.field_count.value=i;
}else{
alert("최소 1개이상의 Field 가 있어야 합니다.");
}
}

function primary_key()
{
var p_count = document.create_table.field_count.value;
var key_count = document.create_table.create_primary_key.length;
for(i=0; i==p_count; i++)
{
var optionValue = document.create_table['create_field_name['+i+']'].value;
if(!optionValue)
{
alert("#"+i+"번 Field Name 이 존재 하지 않습니다.");
}else{
for (d=0; d < key_count; d++){
document.create_table.create_primary_key.options.remove(0);
}
var newItem = new Option;
newItem.text = optionValue;
newItem.value = optionValue;
document.create_table.create_primary_key.options[document.create_table.create_primary_key.length]=newItem;
}
}
}

function datetype(type, j_no)
{
var j = j_no;
var type = type;
var date_type_len = "int-4^char-8^varchar-80^text-65535";
var date_type = date_type_len.split("^");
for(f=0; f<date_type.length; f++)
{
var date_len = date_type[f].split("-");
if(date_len[0] == type)
{
document.create_table["create_date_len["+j+"]"].value = date_len[1];
}
}


}

</script>
<body onLoad="add_field()">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class='ht'>
<td align=left><?=subtitle("Db 생성")?></td>
</tr>
<tr>
<td class=line1>
</td>
</tr>
<tr>
<td>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<form name="create_table" method="post" action="<?=$g4['admin_path']?>/create_table_update.php">
<input name="field_count" type="hidden" value=0><input name="field_namelist" type="hidden" value="Primary Key 를 선택해주세요">
<tr>
<td>

<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150" align="center">Table Name</td>
<td>
<input type="text" name="create_table_name" style="width:300px; background-color:#f6f6f6; border:1px solid #d8d8d5; height:21px;" itemname="Table Name" required>
</td>
</tr>
</table>

</td>
</tr>
<tr>
<td height="5"></td>
</tr>
<tr>
<td height="1" bgcolor="#CCCCCC"></td>
</tr>
<tr>
<td height="5"></td>
</tr>
<tr>
<td>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150" align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">Date Field 추가</td>
</tr>
<tr>
<td height="5" align="center"></td>
</tr>
<tr>
<td align="center"><span onClick="add_field();" style="cursor:pointer;">+</span>  <span onClick="del_field();" style="cursor:pointer;">-</span></td>
</tr>
</table></td>
<td>

<table border="0" id="table_field" cellspacing="1" cellpadding="0">
<tr>
<td width="50" align="center" bgcolor="#CBB08D" class="field_title">NO</td>
<td width="200" align="center" bgcolor="#CBB08D" class="field_title">Field Name</td>
<td width="180" align="center" bgcolor="#CBB08D" class="field_title">Date Type</td>
<td width="100" align="center" bgcolor="#CBB08D" class="field_title">Date length</td>
<td width="120" align="center" bgcolor="#CBB08D" class="field_title">NULL</td>
</tr>


</table>


</td>
</tr>
</table>



</td>
</tr>
<tr>
<td height="5"></td>
</tr>
<tr>
<td height="1" bgcolor="#CCCCCC"></td>
</tr>
<tr>
<td height="5"></td>
</tr>
<tr>
<td>

<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150" align="center">PRIMARY KEY</td>
<td>
<select name="create_primary_key" onFocus="primary_key()" style="width:160px; background-color:#f6f6f6; border:1px solid #d8d8d5; height:21px;" itemname="PRIMARY KEY" required>
<option selected>Primary Key</option>
</select>
</td>
</tr>
</table>

</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td class=line1>
</td>
</tr>
<tr>
<td align="right"><input type="submit" name="button" id="button" value="Table 생성" /></td>
</tr>
<tr>
<td> </td>
</tr>
</form>
</table>


</td>
</tr>
</table>
|

댓글 2개

for문이 잘못된것 같은데요..

for(i=0; i<=p_count; i++)

이처럼 작성해야 할것 같습니다..
그럼 optionValue는 잡아 내는데..
오타이신것 같네요.. ㅎㅎ
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
11-08-16 조회 2,458
11-08-16 조회 2,451
11-08-12 조회 2,282
11-08-02 조회 2,861
11-07-27 조회 2,238
11-07-25 조회 2,351
11-06-28 조회 2,553
11-06-06 조회 4,063
11-06-04 조회 2,640
11-04-25 조회 6,222
11-04-22 조회 2,726
11-04-21 조회 2,957
11-04-08 조회 3,371
11-03-31 조회 2,877
11-03-20 조회 3,305
11-03-10 조회 2,904
11-03-04 조회 3,219
11-03-03 조회 2,954
11-02-26 조회 4,389
11-02-14 조회 5,738
11-02-08 조회 3,339
11-01-30 조회 5,429
11-01-14 조회 5,234
11-01-14 조회 3,782
11-01-14 조회 2,932
11-01-14 조회 2,963
11-01-14 조회 3,118
11-01-12 조회 2,892
11-01-07 조회 4,540
10-12-29 조회 2,560
10-12-22 조회 2,504
10-12-05 조회 5,908
10-11-22 조회 5,279
10-11-13 조회 3,648
10-10-27 조회 3,256
10-10-21 조회 2,966
10-09-21 조회 2,958
10-09-17 조회 3,024
10-09-15 조회 3,465
10-09-14 조회 4,068
10-05-18 조회 2,964
10-02-17 조회 4,397
10-02-12 조회 3,151
09-12-14 조회 5,222
09-12-14 조회 6,088
09-09-19 조회 4,439
09-08-16 조회 6,301
09-07-22 조회 5,700
09-04-13 조회 3,095
09-03-15 조회 5,113
09-03-05 조회 3,943
09-02-09 조회 2,895
08-12-30 조회 3,074
08-12-06 조회 3,271
08-11-30 조회 3,612
08-10-18 조회 4,461
08-10-08 조회 3,847
08-09-19 조회 4,419
08-09-05 조회 3,050
08-09-05 조회 5,146
08-09-05 조회 3,021
08-09-05 조회 3,629
08-09-05 조회 3,536
08-09-01 조회 4,554
08-08-07 조회 2,803
08-06-08 조회 3,266
08-06-02 조회 2,874
08-05-26 조회 5,290
08-05-09 조회 4,346
08-04-22 조회 3,971
08-04-17 조회 4,540
08-04-17 조회 5,609
08-04-17 조회 3,754
08-04-17 조회 8,738
08-04-17 조회 4,652
08-04-17 조회 4,564
08-04-09 조회 3,103
08-03-31 조회 3,582
08-03-26 조회 3,307
08-03-25 조회 3,589
08-03-25 조회 4,011
08-03-25 조회 4,038
08-03-25 조회 3,702
08-03-25 조회 3,597
08-03-25 조회 3,605
08-03-25 조회 5,299
08-02-03 조회 5,382
08-01-18 조회 6,679
08-01-17 조회 3,970
08-01-17 조회 3,788
08-01-12 조회 4,091
08-01-08 조회 3,403
07-12-28 조회 4,684
07-12-04 조회 3,572
07-11-30 조회 5,174
07-11-30 조회 5,769
07-11-02 조회 4,058
07-10-24 조회 4,043
07-10-24 조회 3,324
07-10-24 조회 3,431