|
 |
|
สอบถามการใช้ list menu โดยฟังก์ชั่น Onchange ให้แสดงราคาสินค้าในแต่ละ ชนิดสินค้าทำอย่างไร |
|
 |
|
|
 |
 |
|
อยากสอบถามการใช้ list menu เพื่อเลือกรายการสินค้าจาก database แล้ว พอคลิกเลือกเสร็จ ให้แสดงราคา ในช่อง texfield ของแต่ละชนิดประเภทสินค้า สามารถทำได้อย่างไรครับ ตาม code นี้
Code (PHP)
<table width="49%" border="1">
<tr>
<th width="20%" bgcolor="#00FF66" scope="col"><span class="style45">ชนิดสินค้า</span></th>
<th colspan="2" bgcolor="#00FF66" scope="col"><span class="style45">รายละเอียดสินค้า</span></th>
<th width="23%" bgcolor="#00FF66" scope="col"><span class="style45">ราคาสินค้า</span></th>
</tr>
<tr>
<th bgcolor="#00FFFF" scope="row"><span class="style44">CD-ROM</span></th>
<td colspan="2" bgcolor="#FFCCFF"><label for="select"></label>
<div align="left">
<select name="cdromid" id="cdromid" onchange ="this.form.textfield.value = this.value">
<option value="0">--โปรดเลือกรายการ--</option>
<?php
do {
?>
<option value="<?php echo $row_rsCdrom['Price']?>"><?php echo $row_rsCdrom['CdRom']?></option>
<?php
} while ($row_rsCdrom = mysql_fetch_assoc($rsCdrom));
$rows = mysql_num_rows($rsCdrom);
if($rows > 0) {
mysql_data_seek($rsCdrom, 0);
$row_rsCdrom = mysql_fetch_assoc($rsCdrom);
}
?>
</select>
</div></td>
<td bgcolor="#FFFF00"><label for="textfield"></label>
<div align="center">
<input name="price1" type="text" id="textfield" size="18" />
</div></td>
</tr>
<tr>
<th bgcolor="#00FFFF" scope="row"><span class="style44">CPU</span></th>
<td colspan="2" bgcolor="#FFCCFF"><label for="select"></label>
<div align="left">
<select name="cpuid" id="cpuid" >
<option value="0">--โปรดเลือกรายการ--</option><?php
do {
?><option value="<?php echo $row_rsCpu['CPU']?>"><?php echo $row_rsCpu['CPU']?></option>
<?php
} while ($row_rsCpu = mysql_fetch_assoc($rsCpu));
$rows = mysql_num_rows($rsCpu);
if($rows > 0) {
mysql_data_seek($rsCpu, 0);
$row_rsCpu = mysql_fetch_assoc($rsCpu);
}
?>
</select>
</div></td>
<td bgcolor="#FFFF00"><div align="center">
<input name="price2" type="text" id="price2" size="18" />
</div></td>
</tr>
<tr>
<th bgcolor="#00FFFF" scope="row"><span class="style44">Harddisk</span></th>
<td colspan="2" bgcolor="#FFCCFF"><label for="select"></label>
<div align="left">
<select name="harddiskid" id="harddiskid">
<option value="0">--โปรดเลือกรายการ--</option>
<?php
do {
?><option value="<?php echo $row_rsHarddisk['HardDisk']?>"><?php echo $row_rsHarddisk['HardDisk']?></option>
<?php
} while ($row_rsHarddisk = mysql_fetch_assoc($rsHarddisk));
$rows = mysql_num_rows($rsHarddisk);
if($rows > 0) {
mysql_data_seek($rsHarddisk, 0);
$row_rsHarddisk = mysql_fetch_assoc($rsHarddisk);
}
?>
</select>
</div></td>
<td bgcolor="#FFFF00"><div align="center">
<input name="price3" type="text" id="price3" size="18" />
</div></td>
</tr>
<tr>
<th bgcolor="#00FFFF" scope="row"><span class="style44">Mainboard</span></th>
<td colspan="2" bgcolor="#FFCCFF"><label for="select"></label>
<div align="left">
<select name="mainboardid" id="mainboardid">
<option value="0">--โปรดเลือกรายการ--</option>
<?php
do {
?><option value="<?php echo $row_rsMainboard['MainBoard']?>"><?php echo $row_rsMainboard['MainBoard']?></option>
<?php
} while ($row_rsMainboard = mysql_fetch_assoc($rsMainboard));
$rows = mysql_num_rows($rsMainboard);
if($rows > 0) {
mysql_data_seek($rsMainboard, 0);
$row_rsMainboard = mysql_fetch_assoc($rsMainboard);
}
?>
</select>
</div></td>
<td bgcolor="#FFFF00"><div align="center">
<input name="price4" type="text" id="price4" size="18" />
</div></td>
</tr>
<tr>
<th bgcolor="#00FFFF" scope="row"><span class="style44">Monitor</span></th>
<td colspan="2" bgcolor="#FFCCFF"><label for="select"></label>
<div align="left">
<select name="monitorid" id="monitorid">
<option value="0">--โปรดเลือกรายการ--</option>
<?php
do {
?><option value="<?php echo $row_rsMonitor['Monitor']?>"><?php echo $row_rsMonitor['Monitor']?></option>
<?php
} while ($row_rsMonitor = mysql_fetch_assoc($rsMonitor));
$rows = mysql_num_rows($rsMonitor);
if($rows > 0) {
mysql_data_seek($rsMonitor, 0);
$row_rsMonitor = mysql_fetch_assoc($rsMonitor);
}
?>
</select>
</div></td>
<td bgcolor="#FFFF00"><div align="center">
<input name="price5" type="text" id="price5" size="18" />
</div></td>
</tr>
<tr>
<th bgcolor="#00FFFF" scope="row"><span class="style44">NetworkCard</span></th>
<td colspan="2" bgcolor="#FFCCFF"><label for="select"></label>
<div align="left">
<select name="networdcardid" id="networdcardid">
<option value="0">--โปรดเลือกรายการ--</option>
<?php
do {
?><option value="<?php echo $row_rsNetworkcard['NetWorkCard']?>"><?php echo $row_rsNetworkcard['NetWorkCard']?></option>
<?php
} while ($row_rsNetworkcard = mysql_fetch_assoc($rsNetworkcard));
$rows = mysql_num_rows($rsNetworkcard);
if($rows > 0) {
mysql_data_seek($rsNetworkcard, 0);
$row_rsNetworkcard = mysql_fetch_assoc($rsNetworkcard);
}
?>
</select>
</div></td>
<td bgcolor="#FFFF00"><div align="center">
<input name="price6" type="text" id="price6" size="18" />
</div></td>
</tr>
<tr>
<th bgcolor="#00FFFF" scope="row"><span class="style44">RAM</span></th>
<td colspan="2" bgcolor="#FFCCFF"><label for="select"></label>
<div align="left">
<select name="ramid" id="ramid">
<option value="0">--โปรดเลือกรายการ--</option>
<?php
do {
?><option value="<?php echo $row_rsRam['Ram']?>"><?php echo $row_rsRam['Ram']?></option>
<?php
} while ($row_rsRam = mysql_fetch_assoc($rsRam));
$rows = mysql_num_rows($rsRam);
if($rows > 0) {
mysql_data_seek($rsRam, 0);
$row_rsRam = mysql_fetch_assoc($rsRam);
}
?>
</select>
</div></td>
<td bgcolor="#FFFF00"><div align="center">
<input name="price7" type="text" id="price7" size="18" />
</div></td>
</tr>
<tr>
<th bgcolor="#00FFFF" scope="row"><span class="style44">SoundCard</span></th>
<td colspan="2" bgcolor="#FFCCFF"><label for="select"></label>
<div align="left">
<select name="soundcardid" id="soundcardid">
<option value="0">--โปรดเลือกรายการ--</option>
<?php
do {
?><option value="<?php echo $row_rsSoundcard['SoundCard']?>"><?php echo $row_rsSoundcard['SoundCard']?></option>
<?php
} while ($row_rsSoundcard = mysql_fetch_assoc($rsSoundcard));
$rows = mysql_num_rows($rsSoundcard);
if($rows > 0) {
mysql_data_seek($rsSoundcard, 0);
$row_rsSoundcard = mysql_fetch_assoc($rsSoundcard);
}
?>
</select>
</div></td>
<td bgcolor="#FFFF00"><div align="center">
<input name="price8" type="text" id="price8" size="18" />
</div></td>
</tr>
<tr>
<th bgcolor="#00FFFF" scope="row"><span class="style44">Speaker</span></th>
<td colspan="2" bgcolor="#FFCCFF"><label for="select"></label>
<div align="left">
<select name="speakerid" id="speakerid">
<option value="0">--โปรดเลือกรายการ--</option>
<?php
do {
?><option value="<?php echo $row_rsSpeaker['Speaker']?>"><?php echo $row_rsSpeaker['Speaker']?></option>
<?php
} while ($row_rsSpeaker = mysql_fetch_assoc($rsSpeaker));
$rows = mysql_num_rows($rsSpeaker);
if($rows > 0) {
mysql_data_seek($rsSpeaker, 0);
$row_rsSpeaker = mysql_fetch_assoc($rsSpeaker);
}
?>
</select>
</div></td>
<td bgcolor="#FFFF00"><div align="center">
<input name="price9" type="text" id="price9" size="18" />
</div></td>
</tr>
<tr>
<th bgcolor="#00FFFF" scope="row"><span class="style44">VGA</span></th>
<td colspan="2" bgcolor="#FFCCFF"><label for="select"></label>
<div align="left">
<label for="select"></label>
<select name="vgaid" id="vgaid">
<option value="0">--โปรดเลือกรายการ--</option>
<?php
do {
?><option value="<?php echo $row_rsVga['DisplayCard']?>"><?php echo $row_rsVga['DisplayCard']?></option>
<?php
} while ($row_rsVga = mysql_fetch_assoc($rsVga));
$rows = mysql_num_rows($rsVga);
if($rows > 0) {
mysql_data_seek($rsVga, 0);
$row_rsVga = mysql_fetch_assoc($rsVga);
}
?>
</select>
</div></td>
<td bgcolor="#FFFF00"><label for="label"></label>
<div align="center">
<input name="price10" type="text" id="label" size="18" />
</div></td>
</tr>
<tr>
<th colspan="3" bgcolor="#CC9900" scope="row"><span class="style45">รวมราคาสินค้าที่เลือกทั้งหมด</span></th>
<td bgcolor="#99FFFF"><label for="label2"></label>
<div align="center">
<input name="textfield11" type="text" id="label2" size="18" />
</div></td>
</tr>
</table>
Tag : PHP, MySQL, JavaScript, CakePHP

|
|
 |
 |
 |
 |
Date :
2010-09-03 02:09:19 |
By :
1234567 |
View :
1861 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ให้ใช้...AJAX เข้ามาช่วยครับ...โดยใช้ Onchange="javascript:FUNCTION_NAME(AJAX REQUEST)"
แล้วให้ Ajax ไปคิวรี่ราคาจากที่เราเลือกมาแล้วมากำหนดค่าให้กับ กล่องข้อความของราคาของเรา ทำยังงี้ทุกรายการที่เลือก
ลองดูการใช้ Ajax ได้น่ะครับ....สู้ๆๆ
|
 |
 |
 |
 |
Date :
2010-09-03 14:09:52 |
By :
olekkc |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ จะลองดู 
|
 |
 |
 |
 |
Date :
2010-09-03 20:57:00 |
By :
1234567 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|