【发布时间】:2016-01-11 08:41:17
【问题描述】:
我有一个带有 2 个选项(本地和进口)的下拉列表。如果我选择 LOCAL,我应该得到值 LOC,而 IMPORT,我应该得到 IM。但无论是我选择的两个,我都得到了价值 IM。请帮忙,如何获取对应select选项的值。谢谢。
<?php $shipmenttype = array("0"=>"Please select", "LOC"=>"LOCAL", "IM"=>"IMPORT");?>
<td><b><select name='shiptype' id='shiptype' onchange=''>
<?php foreach($shipmenttype as $keyname=>$ship_type):?>
<?php
$selected = "";
$shiptype = $_POST['shiptype'];
if($keyname == $shiptype): $selected =" selected"; endif;
?>
<option value="<?php echo $keyname;?>" <?php echo $selected;?>><?php echo $ship_type;?></option>
<?php endforeach;?>
</select></b></td></tr>
<?php
$site = dbGetConfig("sitecode");
$dbnextID = dbNextID($keyname);
if($site=="CKI") {
$site="CK".date("Y");
}
if($site=="PQI") {
$site="PQ".date("Y");
}
$refnumb = $keyname.$site."-".str_pad($dbnextID,7,0, STR_PAD_LEFT);
?>
运行编号(000000):
function dbNextID($key) {
$sql1 = "insert into key_master (keyname) values (:keyname)";
$sql2= "update key_master set id = id + 1 where keyname = :keyname";
$sql3 = "select id from key_master where keyname = :keyname";
$conn = dbConnect();
$stmt1 = $conn->prepare($sql1);
$stmt2 = $conn->prepare($sql2);
$stmt3 = $conn->prepare($sql3);
$conn->beginTransaction();
$stmt1->execute(array(':keyname' => $key));
$stmt2->execute(array(':keyname' => $key));
$stmt3->execute(array(':keyname' => $key));
$value = $stmt3->fetchColumn(0);
$conn->commit();
$conn=null;
return $value;
}
HTML 表格:
<!--- Local Shipment --->
<table id="t1" class=normal2 style='font-size:0.6em;'>
<tr><th align='right'>Shipment Type:</th>
<td><b><input type='text' name='ship1' id='ship1' value="" readonly /></b></td></tr>
<tr><th align='right'>Reference Number: </th>
<td><input type='text' name='ref_no1' id='ref_no1' value="<?php echo $refnumb ?>" readonly /></td></tr>
<tr><th align='right'>Supplier: </th>
<td><select name='supplier1'>
<?php foreach($data1 as $row1): ?>
<option value="<?php echo $row1['SupplierName'] ?>"><?php echo $row1['SupplierName'] ?></option>
<?php endforeach; ?>
</select></td></tr>
<tr><th align='right'>Description: </th>
<td><input type='text' name='description1' size='70' /></td></tr>
<tr><th align='right'>PO No: </th>
<td><input type='date' name='po_no1' /></td></tr>
<tr><th align='right'>Invoice Number: </th>
<td><input type='text' name='inv_number1' /></td></tr>
<tr><th align='right'>Receive Qty: </th>
<td><input type='text' name='r_qty1' /></td></tr>
<tr><th align='right'>No. of Boxes/Packs: </th>
<td><input type='text' name='no_boxes1' /></td></tr>
<tr><th align='right'></th>
<td></td></tr>
<tr><th align='right'> </th>
<td align='left'><input type='submit' name='local_add' value='SAVE' style='font-size:2em;' /> <input type='submit' name='local_cancel' value='CANCEL' style='font-size:2em;' /></td></tr>
</table>
<!--- Import Shipment --->
<table id="t2" class=normal2 style='font-size:0.6em;'>
<tr><th align='right'>Shipment Type:</th>
<td><b><input type='text' name='ship2' id='ship2' value="" readonly /></b></td></tr>
<tr><th align='right'>Reference Number: </th>
<td><b><input type='text' name='ref_no2' id='ref_no2' value="<?php echo $refnumb ?>" readonly /></b></td></tr>
<tr><th align='right'>Supplier: </th>
<td><select name='supplier2'>
<?php foreach($data2 as $row2): ?>
<option value="<?php echo $row2['SupplierName'] ?>"><?php echo $row2['SupplierName'] ?>
<?php endforeach; ?>
</select></td></tr>
<tr><th align='right'>Description: </th>
<td><input type='text' name='description2' size='70' /></td></tr>
<tr><th align='right'>PO No: </th>
<td><input type='date' name='po_no2' /></td></tr>
<tr><th align='right'>Invoice Number: </th>
<td><input type='text' name='inv_number2' /></td></tr>
<tr><th align='right'>AWB(Airway Bill) No: </th>
<td><input type='text' name='awb_no2' /></td></tr>
<tr><th align='right'>AWB No of Boxes/Packs: </th>
<td><input type='text' name='awb_no_boxes2' /></td></tr>
<tr><th align='right'> </th>
<td></td></tr>
<tr><th align='right'> </th>
<td align='left'><input type='submit' name='import_add' value='SAVE' style='font-size:2em;' /> <input type='submit' name='import_cancel' value='CANCEL' style='font-size:2em;' /></td></tr>
</table>
jquery:
<script>
$('#shiptype').change(function () {
$('#t1,#t2').hide();
var selectedValue = $(this).val();
var strloc = "LOCAL";
var strimp = "IMPORT";
if (selectedValue == "LOC") {
$('#t1').show();
$('#ship1').val(strloc);
//$('#strkey').val(selectedValue);
} else if (selectedValue == "IM") {
$('#t2').show();
$('#ship2').val(strimp);
//$('#strkey').val(selectedValue);
}
});
$('#t1,#t2').hide();
</script>
【问题讨论】:
-
如何在一个下拉菜单中选择两个选项?请简要解释一下。
-
您问题中的代码看起来没问题。请在您评估下拉列表中所选选项的位置添加代码。
-
你在寻找多种选择吗??
-
@mapek 请在上面查看我更新的代码。