我是一个更新鲜的PHP,想要知道如何选中动态复选框时获取动态文本框值,例如羊肉骨是一个复选框和羊肉无骨在一个复选框(复选框来动态)如果用户检查羊肉骨的价格将被提取并显示在一个文本框中。想知道如果选中复选框时如何获取价格值。
<?php
$query = mysql_query("select distinct type_categ from prod_type");
$count = mysql_num_rows($query);
if($count > 0) {
while($row =mysql_fetch_array($query)) {
?>
<div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="landmark">
<?php echo $row['type_categ']; ?>
</label>
<input type="checkbox" name="bone[]" id="" class="<?php echo $row['type_categ'].','; ?>Bone" value="<?php echo $row['type_categ'].','; ?>bone" > <?php echo $row['type_categ']; ?>Bone
<input type="checkbox" name="bone[]" class="<?php echo $row['type_categ'].','; ?>Bone less" value="<?php echo $row['type_categ'].','; ?>boneless"/> <?php echo $row['type_categ']; ?> Bone Less
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="kilo" onblur="calculate()" placeholder="Enter Kg" class="optional form-control col-md-7 col-xs-12 input <?php echo $result['type_categ'].'c'; ?>">
<br>
<br>
<input type="text" name="price" onblur="calculate()" placeholder="Amount" class="optional form-control col-md-7 col-xs-12 input <?php echo $result['type_categ'].'d'; ?>">
<br>
<br>
<input id="<?php echo $row['type_categ'].','; ?>Bone" type="text" name="kiloo" onblur="calculate()" class="optional form-control col-md-7 col-xs-12 pricek input <?php echo $result['type_categ'].'e'; ?>" readonly>
<input type="checkbox" name="gravy[]" value="<?php echo $row['type_categ'].','; ?>gravy" >Gravy
<input type="checkbox" name="gravy[]" value="<?php echo $row['type_categ'].','; ?>chilly"/> Chilly
<input type="checkbox" name="gravy[]" value="<?php echo $row['type_categ'].','; ?>briyani"/> Briyani
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="landmark">Pieces
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="checkbox" name="pieces[]" value="<?php echo $row['type_categ']; ?>large" >Large
<br>
<input type="checkbox" name="pieces[]" value="<?php echo $row['type_categ']; ?>medium" >Medium
<br>
<input type="checkbox" name="pieces[]" value="<?php echo $row['type_categ']; ?>small">Small
</div>
</div>
</form>
</div>
<?php } } ?>
<button id="send" type="submit" name="order" class="btn btn-success">Submit</button>
<script>
$('input[type=checkbox]').click(function(){
if ($(this).is(':checked')) {
var product = $(this).attr("class");
var arr = product.split(',');
var pro = $(this).val();
}
else{
$(this).val('0');
var product = $(this).attr("class");
var arr = product.split(',');
var pro = $(this).val();
}
$.ajax({
url:'js/edit_page.php',
type:'GET',
data:({product: arr[1] ,pro: pro ,proe: arr[0]}),
dataType:'json',
success:function(data){
$(".pricek").val(data.price);
$(".type_categ").val(data.type_categ);
$(".type_prod").val(data.type_prod);
}
});
});
</script>