我对此感到困惑。我有这样的HTML文件:
$(document).ready(function() {
$('select.supplier').change(function() {
var capacityValue = $('select.supplier').find(':selected').data('capacity');
$('.supplierCapacity').val(capacityValue);
});
});
$(document).ready(function() {
$('select.supplier').change(function() {
var countryValue = $('select.supplier').find(':selected').data('country');
$('.supplierCountry').val(countryValue);
});
});
select,
input {
padding: 5px;
margin: 5px 0 10px;
font-weight: bold;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Choose Supplier :
<br>
<form method="post" action="submit.php">
<select class="supplier" name="supplier">
<option data-country="Argentine" data-capacity="100" value="10">Johny Farms</option>
<option data-country="Belgium" data-capacity="200" value="20>">Jack & Jane Farms</option>
<option data-country="Canada" data-capacity="300" value="30">Crabs Crane</option>
</select><br>
<input type="hidden" name="supplierCapacity" class="supplierCapacity" readonly /><br>
Country :<br>
<input type="text" name="supplierCountry" class="supplierCountry" readonly /><br>
<input type="submit" value=" save ">
</form>
如何获取要发布的输入值。我在submit.php中编写了这段代码但不起作用:
$capacity = $_POST['supplierCapacity'];
$country = $_POST['supplierCountry'];
答案 0 :(得分:0)
为输入添加ID
<input id="testing" />
在javascript中,获取输入值
document.getElementId('testing').value
或
$('#testing').val();