我正在尝试2个选择,一个是请求类型,一个是请求编号 像这样:
代码如下:
<td>Request Type</td>
<select name='cr_type' id='cr_type' >
<option value=''>-Pilih-</option>
<option value='CR'>CR</option>
<option value='PR'>PR</option>
<option value='BR'>BR</option>
<option value='T'>T</option>
<option value='BPI'>BPI</option>
<td>Request Number</td>
<select name='cr_code' id='cr_code' >
<option value=''>-Pilih-</option>
<option value='CR'>CR</option>
<option value='PR'>PR</option>
<option value='BR'>BR</option>
<option value='T'>T</option>
并且我想这样做,以便如果我选择CR,PR,BR和T,它们将自动生成相应类型的请求号(CR转换为CR,PR转换为PR,BR转换为BR和T进入T),然后将其禁用以使其无法更改。如果我选择BPI,他们会变成手动选择CR,PR和BR。
答案 0 :(得分:0)
var crType = document.getElementById("cr_type"),
crCode = document.getElementById("cr_code");
crType.onchange = function() {
var value = crType.value;
if (value !== 'BPI') {
crCode.value = value;
crCode.disabled = true;
} else {
crCode.value = '';
crCode.disabled = false;
}
};
<td>Request Type</td>
<select name='cr_type' id='cr_type'>
<option value=''>-Pilih-</option>
<option value='CR'>CR</option>
<option value='PR'>PR</option>
<option value='BR'>BR</option>
<option value='T'>T</option>
<option value='BPI'>BPI</option>
</select>
<br>
<td>Request Number</td>
<select name='cr_code' id='cr_code' >
<option value=''>-Pilih-</option>
<option value='CR'>CR</option>
<option value='PR'>PR</option>
<option value='BR'>BR</option>
<option value='T'>T</option>
</select>
答案 1 :(得分:0)
如果我理解正确,您可以在下面获取代码: (您的页面上需要有jQuery库)
<td>Request Type</td>
<select name='cr_type' id='cr_type'>
<option value=''>-Pilih-</option>
<option value='CR'>CR</option>
<option value='PR'>PR</option>
<option value='BR'>BR</option>
<option value='T'>T</option>
<option value='BPI'>BPI</option>
</select>
<td>Request Number</td>
<select name='cr_code' id='cr_code'>
<option value=''>-Pilih-</option>
<option value='CR'>CR</option>
<option value='PR'>PR</option>
<option value='BR'>BR</option>
<option value='T'>T</option>
</select>
<script type="text/javascript">
$(document).ready(function () {
$('#cr_type').on('change', function () {
var crVal = $(this).val(),
crCode = $('#cr_code'),
optionT = crCode.find('option[value="T"]');
if ("BPI" === crVal) {
optionT.attr('disabled', 'disabled');
crCode.val('');
} else {
optionT.removeAttr('disabled');
crCode.val(crVal);
}
});
});
</script>
答案 2 :(得分:0)
这是我的希望,希望能解决您的问题
<form method="post">
<td>Request Type</td>
<select name='cr_type' id='cr_type' onchange="submit()">
<option value=''>-Pilih-</option>
<option value='CR'>CR</option>
<option value='PR'>PR</option>
<option value='BR'>BR</option>
<option value='T'>T</option>
<option value='BPI'>BPI</option>
</select>
<br>
<td>Request Number</td>
<?php if(($_POST['cr_type']=="BPI")){ ?>
<select name='cr_code' id='cr_code' >
<option value=''>-Pilih-</option>
<option value='CR'>CR</option>
<option value='PR'>PR</option>
<option value='BR'>BR</option>
<option value='T'>T</option>
</select>
<?php }else if(($_POST['cr_type']!="BPI")){ ?>
<input type="text" name="" value="<?php echo $_POST['cr_type'] ?>" readonly>
<?php }else if(!isset($_POST['cr_type'])){ ?>
Silakan Pilih request Type
<?php } ?>
</form>
<script type="text/javascript">
document.getElementById('cr_type').value = "<?php echo $_POST['cr_type'];?>";
</script>