เทพทุกท่านช่วยที อยากได้ javascript ตอนเลือกเดือนที่ dropdownlist แล้วทำให้ field อื่นๆเปลี่ยนตาม
โค้ดประมาณนี้
<?
ob_start();
@session_start();
include("includes/function.php");
include("includes/dbconnect.inc.php");
$toptitle = "นำเข้าข้อมูลรายการสินทรัพย์ของโรงงาน";
if(isset($btnaddasset))
{
$setyear= substr($year,2,2);
$txtmontof = getdoc_no($ddlmonth);
$set_month = set_month($ddlmonth);
$txtdocnum = "$rdoatcp-$setyear-$set_month-$txtmontof";
$strinsert = "INSERT INTO tb_asset(
month, monthof_no, doc_no, asstype_no, asset_number, old_location, new_location,
old_cost, new_cost, old_person, new_person, stamp_by)
VALUES('$set_month', '$txtmontof', '$txtdocnum', $ddltypelist, '$txtasset_number', '$txtold_location', '$txtnew_location',
'$txtold_cost', '$txtnew_cost', '$txtold_person', '$txtnew_person', '$txtstamp_by')";
$dbquery = mysql_db_query($dbName, $strinsert);
}
?>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<link rel="stylesheet" type="text/css" href="includes/mystyle.css"/>
<title><? echo"$toptitle $year"; ?></title>
<script language="javascript" type="text/javascript">
function checksubmit()
{
if(document.frmdisplay.txtasset_number.value.length==0)
{
alert("กรุณากรอกข้อมูลให้ครบถ้วน ");
document.frmdisplay.txtasset_number.focus();
return false;
}
}
function getno_document(radioObj)
{
if(document.frmdisplay.rdoatcp[0].checked==true)
{
radioObj = 'BK';
}
else{
radioObj = 'OT';
}
var keed='-';
var txtmontof = document.frmdisplay.txtmontof.value;
<?
$year = getyeartwodigit("Y");
$month = getyeartwodigit("m");
?>
x = <?=substr($year,2,2);?>;
y = document.frmdisplay.ddlmonth.options[document.frmdisplay.ddlmonth.selectedIndex].value
if(y.length==1)
{
zero = "0";
}else{zero="";}
document.frmdisplay.txtdocnum.value = radioObj+keed+x+keed+zero+y+keed+txtmontof;
return (document.frmdisplay.txtdocnum.value);
}
</script>
</head>
<body onLoad="getno_document(frmdisplay.rdoatcp.value);">
<table width="100%" border="0" cellspacing="0px" cellpadding="0px" align="center">
<tr>
<td width="5px" height="0px"></td>
<td> </td>
<td width="5px"></td>
</tr>
<tr>
<td></td>
<td valign="top">
<form id="frmdisplay" name="frmdisplay" method="POST" action="display.php" >
<table width="100%" border="0" align="center" class="issute" cellspacing="2px">
<?
$sql = "select MAX(asset_no) from tb_asset order by asset_no DESC";
$result = mysql_query($sql);
$numasset = @mysql_num_rows($result);
$numasset = numasset+1;
?>
<tr>
<td width="15%"><div align="right">รายการสินทรัพย์ของ :</div></td>
<td colspan="2" width="85%">
<table border="0" align="left" class="issute" cellspacing="0px">
<tr>
<td>กรุงเทพ </td>
<td><input type="radio" name="rdoatcp" value="BK" checked onClick="getno_document(this.value)"></td>
<td width="10px"></td>
<td> อื่นๆ </td>
<td><input type="radio" name="rdoatcp" value="OT" onClick="getno_document(this.value)"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%"><div align="right">เลขที่ :</div></td>
<td colspan="2"><input name="txtasset_no" type="text" value="<? echo"$numasset"; ?>" style="width:90" disabled></td>
</tr>
<tr>
<td><div align="right">เดือน :</div></td>
<td colspan="2"><input name="lblmonth" type="hidden" readonly value="<? echo"$month"; ?>" size="2" disabled>
<select name="ddlmonth" style="width:90px" onChange="getno_document(rdoatcp.value)">
<? loopmonth($month); ?>
</select>
</td>
</tr>
<?
$monthof_no = getdoc_no($ddlmonth);
?>
<tr>
<td><div align="right">ลำดับที่ :</div></td>
<td colspan="2"><input name="txtmontof" type="text" disabled value="<? echo"$monthof_no"; ?>" style="width:90px;"></td>
</tr>
<tr>
<td><div align="right">No. :</div></td>
<td colspan="2"><input name="txtdocnum" type="text" value="<? echo"$doc_no";?>" disabled style="width:90px;"></td>
</tr>
<tr>
<td><div align="right">วัน/เดือน/ปี ที่กรอก :</div></td>
<td colspan="2"><input name="txtstampdate" type="text" disabled value="<? echo"$year";?>" style="width:90px;"></td>
</tr>
<tr>
<td><div align="right">ชนิดของใบรายการ :</div></td>
<td colspan="2">
<select name="ddltypelist" >
<?
$sqltypelist = "select * from tb_assettype order by asstype_name ";
echo"$sqltypelist";
$resultlist = @mysql_query($sqltypelist);
$numlist = @mysql_num_rows($resultlist);
$i = 0;
while($i < $numlist)
{
$rowl = @mysql_fetch_array($resultlist);
$type_name = $rowl["asstype_name"];
$type_no = $rowl["asstype_no"];
echo"<option value=\"$type_no\" ";
if($type_no==$ddltypelist){echo"selected";}
echo">$type_name</option>";
$i++;
}
?>
</select>
</td>
</tr>
<tr>
<td><div align="right">เลขที่ Asset, เลขที่ PR :</div></td>
<td colspan="2"><textarea name="txtasset_number" cols="70" rows="5" ></textarea></td>
</tr>
<tr>
<td><div align="right">Location เดิม :</div></td>
<td width="35%"><input name="txtold_location" type="text" style="width:100px">
</td>
<td width="65%">
<table width="100%" border="0" align="center" class="issute" cellspacing="0px">
<tr>
<td width="120px"><div align="right">Location ใหม่ :</div></td>
<td><input name="txtnew_location" type="text" style="width:100px;"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><div align="right">Cost center เดิม :</div></td>
<td><input name="txtold_cost" type="text" style="width:100px;"></td>
<td>
<table width="100%" border="0" align="center" class="issute" cellspacing="0px">
<tr>
<td width="120px"><div align="right">Cost center ใหม่ :</div></td>
<td><input name="txtnew_cost" type="text" style="width:100px;"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><div align="right">Personal เดิม :</div></td>
<td><input name="txtold_person" type="text" style="width:100px;"></td>
<td>
<table width="100%" border="0" align="center" class="issute" cellspacing="0px">
<tr>
<td width="120px"><div align="right">Personal ใหม่ :</div></td>
<td><input name="txtnew_person" type="text" style="width:100px;"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><div align="right">ผู้บันทึกรายการ :</div></td>
<td><input name="txtstamp_by" type="text" style="width:100px;"></td>
<td> </td>
</tr>
<tr>
<td><div align="right"></div></td>
<td>
<label>
<input alt="เพิ่มรายการสินทรัพย์" type="submit" name="btnaddasset" value="Add Asset" onClick="javascript:return checksubmit()" />
</label>
</td>
<td> </td>
</tr>
</table>
</form>
</td>
<td> </td>
</tr>
<tr>
<td></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td></td>
<td>
<table width="100%" border="1px" cellpadding="0" cellspacing="0" align="center" class="issute" >
<tr bordercolor="#EEEEEE" align="center">
<td>เลขที่</td>
<td>เดือน</td>
<td>ลำดับที่</td>
<td>No.</td>
<td>วัน/เดือน/ปีที่กรอก</td>
<td>ชนิดของใบรายการ</td>
<td>เลขที่ Asset, เลขที่ PR</td>
<td>Location เดิม</td>
<td>Location ใหม่</td>
<td>Cost center เดิม</td>
<td>Cost center ใหม่</td>
<td>Personal เดิม</td>
<td>Personal ใหม่</td>
<td>ผู้บันทึกรายการ</td>
<td>Edit</td>
<td>Delete</td>
</tr>
<?
$strall = "SELECT ass.asset_no, ass.month, ass.monthof_no, ass.doc_no, ass.stampdate, ass.asstype_no , ass.asset_number,
ass.old_location, ass.new_location, ass.old_cost, ass.new_cost, ass.old_person, ass.new_person, ass.stamp_by, asty.asstype_name
FROM tb_asset as ass LEFT JOIN tb_assettype as asty ON ass.asstype_no = asty.asstype_no
ORDER BY ass.asset_no DESC";
$resultall = mysql_query($strall);
$numrows = @mysql_num_rows($resultall);
$i=0;
while($i<$numrows)
{
$rowe = @mysql_fetch_array($resultall);
$asset_no = $rowe['asset_no'];
$month = $rowe['month'];
$monthof_no = $rowe['monthof_no'];
$doc_no = $rowe['doc_no'];
$stampdate = $rowe['stampdate'];
$asstype_no = $rowe['asstype_no'];
$asset_number = $rowe['asset_number'];
$old_location = $rowe['old_location'];
$new_location = $rowe['new_location'];
$old_cost = $rowe['old_cost'];
$new_cost = $rowe['new_cost'];
$old_person = $rowe['old_person'];
$new_person = $rowe['new_person'];
$stamp_by = $rowe['stamp_by'];
$asstype_name = $rowe['asstype_name'];
?>
<tr>
<td><? echo "$asset_no" ;?></td>
<td><? echo "$month"; ?></td>
<td><? echo "$monthof_no"; ?></td>
<td><? echo "$doc_no"; ?></td>
<td><? echo "$stampdate"; ?></td>
<td><? echo "$asstype_name"; ?></td>
<td><? echo "$asset_number"; ?></td>
<td><? echo "$old_location"; ?></td>
<td><? echo "$new_location"; ?></td>
<td><? echo "$old_cost"; ?></td>
<td><? echo "$new_cost"; ?></td>
<td><? echo "$old_person"; ?></td>
<td><? echo "$new_person"; ?></td>
<td><? echo "$stamp_by"; ?></td>
<td> <? if(isset($asset_no))
{echo"<a href=\"?action=editasset&asset_no=$asset_no\" target=\"_self\"><img src=\"img_use/edit.png\" alt=\"แก้ไขข้อมูล Asset\" border=0></a>";}
else{echo"<img src=\"img_use/edit.png\" border=0>";} ?></td>
<td> </td>
</tr>
<?
$i++;
}
?>
</table>
</td>
<td> </td>
</tr>
</table>
</body>
</html>
Date :
2010-07-13 13:21:08
By :
sugardady
แนะนำให้ไปอ่าน ajax ของ jquery ก่อนครับ มันต้องใช้ ajax ละ
Date :
2010-07-13 14:13:23
By :
plakrim
ขอโคดหน่อยค่ะ
Date :
2010-07-13 15:21:14
By :
sugardady
Load balance : Server 01