select 셀렉트박스, 자바스크립을 이용한 동적폼~
페이지 정보
본문
1.테이블생성
mysql> create table test (name varchar(10) not null primary key,
-> price int(6),
-> delete_code enum('O','X'));
2.데이터 입력
mysql> insert into test values
-> ('새우깡','500','O');
mysql> insert into test values
-> ('부라보콘','1000','O');
mysql> insert into test values
-> ('가나초콜렛','1000','X');
mysql> insert into test values
-> ('뽀빠이','50','X');
3.소스
<?
// 동적셀렉트박스 응용
// www.metalman.pe.kr
// 김명일(kmi101@hanmail.net)
//데이타 베이스연결
include("../inc/db_connect.php");
?>
<html>
<head>
<title>주문폼(예제)</title>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
// 제품가격,품절여부 배열생성
function Change_Group() {
<?
$qry1 = "select name from test";
$result1 = mysql_query($qry1);
$i = 1;
while ($row1 = mysql_fetch_array($result1)) {
$qry2 = "select price from test where name = '$row1[0]'";
$result2 = mysql_query($qry2);
// 가격 배열 생성
echo "if (document.order_form.sangpoom.options[$i].selected == true) { ";
echo "Group2 = new Array();";
echo "Group3 = new Array();";
$j = 0;
// 가격 배열 등록
while ( $row2 = mysql_fetch_array($result2)) {
// 품절여부 배열 생성
echo "Group3[$j] = new Array(); ";
$qry3 = "select delete_code from test where name = '$row1[0]'";
$result3 = mysql_query($qry3);
echo "Group2[$j] = '$row2[0]'; ";
$k = 0;
// 품절여부 배열 등록
while($row3 = mysql_fetch_array($result3)) {
if($row3[0] =='O') {
$row3[0]="판매가능";
}
else {
$row3[0]="품절";
}
echo "Group3[$k] = '$row3[0]'; \n";
}
}
echo "
for ( i = 0 ; i < Group2.length ; i++ ) {
document.order_form.price.value = Group2[i];
}
for ( j = 0 ;j < Group3.length ; j++ ) {
document.order_form.del.value = Group3[j];
}
document.order_form.total.value=(+document.order_form.piece.value*document.order_form.price.value);
}";
$i++;
}
mysql_free_result($result1);
mysql_free_result($result2);
mysql_free_result($result3);
?>
}
</script>
</head>
<body>
<form name="order_form" method="post">
<table border="1" cellspacing="0" cellpadding="0" width="625">
<tr bgcolor=dddddd>
<td width="35">번호</td>
<td width="130">제품명</td>
<td width="60">수량</td>
<td width="60">단가</td>
<td width="60">금액</td>
<td width="80">잔고상태</td>
</tr>
</table>
<table border="1" cellspacing="0" cellpadding="0" width="625">
<tr>
<td width="35">1</td>
<td width="130">
<SELECT name="sangpoom" OnChange="Change_Group()">
<OPTION SELECTED value="0">선택하세요</OPTION>
<?
// 제품명을 리스트 박스에 넣기
$qry = "select name from test";
$result = mysql_query($qry);
while($row = mysql_fetch_array($result)) {
echo "<option value='$row[0]'>$row[0]</option>\n";
}
mysql_free_result($result);
?>
</SELECT></td>
<td width="60"><input type=text size=5 maxlength=4 name="piece" value="1" onblur="document.order_form.total.value=(+document.order_form.piece.value*document.order_form.price.value)"></td>
<td width="60"><input type=text size=10 value="" name="price" style="border: black 0 solid; height: 15; width:60;">
</td>
<td width="60"><input type=text size=10 value="" name="total" style="border: black 0 solid; height: 15; width:60;">
</td>
<td width="80"><input type=text size=10 value="" name="del" style="border: black 0 solid; height: 15; width:80;">
</td>
</tr>
</table>
</form>
</body>
</html>
----------------------phpschool.com에서
mysql> create table test (name varchar(10) not null primary key,
-> price int(6),
-> delete_code enum('O','X'));
2.데이터 입력
mysql> insert into test values
-> ('새우깡','500','O');
mysql> insert into test values
-> ('부라보콘','1000','O');
mysql> insert into test values
-> ('가나초콜렛','1000','X');
mysql> insert into test values
-> ('뽀빠이','50','X');
3.소스
<?
// 동적셀렉트박스 응용
// www.metalman.pe.kr
// 김명일(kmi101@hanmail.net)
//데이타 베이스연결
include("../inc/db_connect.php");
?>
<html>
<head>
<title>주문폼(예제)</title>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
// 제품가격,품절여부 배열생성
function Change_Group() {
<?
$qry1 = "select name from test";
$result1 = mysql_query($qry1);
$i = 1;
while ($row1 = mysql_fetch_array($result1)) {
$qry2 = "select price from test where name = '$row1[0]'";
$result2 = mysql_query($qry2);
// 가격 배열 생성
echo "if (document.order_form.sangpoom.options[$i].selected == true) { ";
echo "Group2 = new Array();";
echo "Group3 = new Array();";
$j = 0;
// 가격 배열 등록
while ( $row2 = mysql_fetch_array($result2)) {
// 품절여부 배열 생성
echo "Group3[$j] = new Array(); ";
$qry3 = "select delete_code from test where name = '$row1[0]'";
$result3 = mysql_query($qry3);
echo "Group2[$j] = '$row2[0]'; ";
$k = 0;
// 품절여부 배열 등록
while($row3 = mysql_fetch_array($result3)) {
if($row3[0] =='O') {
$row3[0]="판매가능";
}
else {
$row3[0]="품절";
}
echo "Group3[$k] = '$row3[0]'; \n";
}
}
echo "
for ( i = 0 ; i < Group2.length ; i++ ) {
document.order_form.price.value = Group2[i];
}
for ( j = 0 ;j < Group3.length ; j++ ) {
document.order_form.del.value = Group3[j];
}
document.order_form.total.value=(+document.order_form.piece.value*document.order_form.price.value);
}";
$i++;
}
mysql_free_result($result1);
mysql_free_result($result2);
mysql_free_result($result3);
?>
}
</script>
</head>
<body>
<form name="order_form" method="post">
<table border="1" cellspacing="0" cellpadding="0" width="625">
<tr bgcolor=dddddd>
<td width="35">번호</td>
<td width="130">제품명</td>
<td width="60">수량</td>
<td width="60">단가</td>
<td width="60">금액</td>
<td width="80">잔고상태</td>
</tr>
</table>
<table border="1" cellspacing="0" cellpadding="0" width="625">
<tr>
<td width="35">1</td>
<td width="130">
<SELECT name="sangpoom" OnChange="Change_Group()">
<OPTION SELECTED value="0">선택하세요</OPTION>
<?
// 제품명을 리스트 박스에 넣기
$qry = "select name from test";
$result = mysql_query($qry);
while($row = mysql_fetch_array($result)) {
echo "<option value='$row[0]'>$row[0]</option>\n";
}
mysql_free_result($result);
?>
</SELECT></td>
<td width="60"><input type=text size=5 maxlength=4 name="piece" value="1" onblur="document.order_form.total.value=(+document.order_form.piece.value*document.order_form.price.value)"></td>
<td width="60"><input type=text size=10 value="" name="price" style="border: black 0 solid; height: 15; width:60;">
</td>
<td width="60"><input type=text size=10 value="" name="total" style="border: black 0 solid; height: 15; width:60;">
</td>
<td width="80"><input type=text size=10 value="" name="del" style="border: black 0 solid; height: 15; width:80;">
</td>
</tr>
</table>
</form>
</body>
</html>
----------------------phpschool.com에서
- 다음글select 문에서 받아온 값 셀렉트 하기 (radio 도 포함) 21.02.09
댓글목록
등록된 댓글이 없습니다.