|
|
|
บรรทัดนี้ไม่ต้อง Refresh ได้ปล่าวครับ อยากให้มันทำงานเหมือน Reset ครับ เพราะ Heading เป็น Flash Load ช้าครับ |
|
|
|
|
|
|
|
Code (PHP)
<td>
เขต <select name="mainSelect" OnChange="this.form.submit()">
<option value=""><-- Please Select Item --></option><?php echo $mainOption; ?>
</select>
</td>
code เต็ม
Code (PHP)
<?php
mysql_connect('localhost', 'test', 'test');
mysql_select_db('test');
mysql_query("SET NAMES tis620");
///////////////////////////////////////////////////////////
function getDistrict($m_slc){
global $price_list; $price_list=array();
$strSQL = "SELECT * FROM price where cfmdist='$m_slc' ORDER BY ctodist";
$rs = mysql_query($strSQL); $price=0;
while($ro = mysql_fetch_assoc($rs)) $price_list[$ro['ctodist']]=$ro; mysql_free_result($rs);
}
///////////////////////////////////////////////////////////
function getOption($slc, $pl){
$txt='';
foreach($pl as $key=>$ro){
$sel=($slc== $ro["ctodist"]? 'SELECTED' : '');
$txt .= "<OPTION VALUE='$ro[ctodist]' $sel >$ro[ctodist]</OPTION>\n";
} mysql_free_result($rs);
return $txt;
}
///////////////////////////////////////////////////////////
function district_js($pl){
$txt='var district=Array()'."\n";
foreach($pl as $key=>$ro){ $txt .= "district['$ro[ctodist]']=$ro[cprice];\n"; }
return $txt;
}
///////////////////////////////////////////////////////////
$mainSelect=isset($_REQUEST['mainSelect'])? $_REQUEST['mainSelect'] : '';
getDistrict($mainSelect);
$mainOption='';
$strSQL = "SELECT cdist FROM district ORDER BY cdist ASC"; // ใช้ ฟีลด์เดียว อย่าอ้าง " * " เปลือง Bandwidth
mysql_query("SET NAMES tis620");
$rs = mysql_query($strSQL);
while($ro = mysql_fetch_assoc($rs)){
$sel=($mainSelect == $ro["cdist"]? 'SELECTED' : '');
$mainOption .= "<OPTION VALUE='$ro[cdist]' $sel >$ro[cdist]</OPTION>\n";
}
mysql_free_result($rs);
$ttl=0;
if($mainSelect){
for ($i=1; $i<5; $i++){
$m='slc'.$i;
$$m=$_REQUEST[$m];
$ttl += $price_list[$$m]['cprice'];
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</head>
<body>
<script language="javascript" type="text/javascript">
<?php echo district_js($price_list); ?>
function getPrice(vl, id){
var prz=document.frmMain['price'+id];
ttl += district[vl] - prz.value;
document.getElementById('ttl').innerHTML = ttl;
prz.value=district[vl];
}
var ttl=<?php echo $ttl; ?>;
</script>
<script language='javascript'>
function clearSelect(){
for(var i=1; i<5; i++){
document.getElementById('slc'+i).selectedIndex=0;
document.getElementById('price'+i).value='0';
}
document.getElementById('ttl').innerHTML=0;
ttl=0;
}
</script>
<form action="" method="post" name="frmMain">
<table border="0" cellpadding="0" cellspacing="0">
<tr><td>เขต <select name="mainSelect" OnChange="this.form.submit()">
<option value=""><-- Please Select Item --></option><?php echo $mainOption; ?>
</select>
</td><td rowspan="5"><center> รวมค่าบริการ <label id="ttl"><?php echo $ttl; ?></label> บาท <br />
<input type="button" value="Reset" onclick="clearSelect()" />
</td></tr>
<tr><td>จุด 1<select id="slc1" OnChange="getPrice( this.value, 1)" style="width: 150px" >
<option value="-"><-- Please Select Item --></option><?php echo getOption($im1, $price_list); ?>
</select><input name="price1" type="text" value="<?php echo $price_list[$im1]['price'];?>" style="width: 60px; text-align: right" /></td></tr>
<tr><td>จุด 2<select id="slc2" OnChange="getPrice( this.value, 2)" style="width: 150px" >
<option value="-"><-- Please Select Item --></option><?php echo getOption($im2, $price_list); ?>
</select><input name="price2" type="text" value="<?php echo $price_list[$im2]['price'];?>" style="width: 60px; text-align: right"/></td></tr>
<tr><td>จุด 3<select id="slc3" OnChange="getPrice( this.value, 3)" style="width: 150px" >
<option value="-"><-- Please Select Item --></option><?php echo getOption($im3, $price_list); ?>
</select><input name="price3" type="text" value="<?php echo $price_list[$im3]['price'];?>" style="width: 60px; text-align: right"/></td></tr>
<tr><td>จุด 4<select id="slc4" OnChange="getPrice( this.value, 4)" style="width: 150px" >
<option value="-"><-- Please Select Item --></option><?php echo getOption($im4, $price_list); ?>
</select><input name="price4" type="text" value="<?php echo $price_list[$im4]['price'];?>" style="width: 60px; text-align: right"/></td></tr>
</table>
</form>
</body>
</html>
Tag : PHP
|
|
|
|
|
|
Date :
2014-07-26 00:09:51 |
By :
jay |
View :
719 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าไม่อยาก Refresh จะต้องใช้พวก Ajax เข้ามาช่วยครับ
jQuery + Ajax
|
|
|
|
|
Date :
2014-07-26 08:10:29 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|