我使用jQuery的单选按钮编写代码。选中单选按钮时,我可以隐藏/显示文本框,它可以工作,但不会将图稿的值插入数据库中。
$Order_date = mysqli_real_escape_string($conn,$_POST['Order_date']);
$Confirm_Design_Date = mysqli_real_escape_string($conn,$_POST['Confirm_Design_Date']);
$Due_Date = mysqli_real_escape_string($conn,$_POST['Due_Date']);
$Name = mysqli_real_escape_string($conn,$_POST['Name']);
$Type_of_Customer = mysqli_real_escape_string($conn,$_POST['Type_of_Customer']);
$phone = mysqli_real_escape_string($conn,$_POST['phone']);
$Email = mysqli_real_escape_string($conn,$_POST['Email']);
$pic = mysqli_real_escape_string($conn,$_POST['pic']);
$design = mysqli_real_escape_string($conn,$_POST['design']);
$Output = mysqli_real_escape_string($conn,$_POST['Output']);
$Finishing = mysqli_real_escape_string($conn,$_POST['Finishing']);
$Submit_date = mysqli_real_escape_string($conn,$_POST['Submit_date']);
$Product = mysqli_real_escape_string($conn,$_POST['Product']);
$Size = mysqli_real_escape_string($conn,$_POST['Size']);
$Material_implode = implode(" , ",$_POST['Material']);
$Material = mysqli_real_escape_string($conn,$Material_implode);
$Type_finishing = mysqli_real_escape_string($conn,$_POST['Type_finishing']);
$Kuantiti = mysqli_real_escape_string($conn,$_POST['Kuantiti']);
$Artwork = mysqli_real_escape_string($conn,$_POST['Artwork']);
$Pengantin_P = mysqli_real_escape_string($conn,$_POST['Pengantin_P']);
$Pengantin_L = mysqli_real_escape_string($conn,$_POST['Pengantin_L']);
$Jum_Hantaran = mysqli_real_escape_string($conn,$_POST['Jum_Hantaran']);
$Bank_pilihan = mysqli_real_escape_string($conn,$_POST['Bank_pilihan']);
$Nama_singkatan = mysqli_real_escape_string($conn,$_POST['Nama_singkatan']);
$Tarikh_akad_nikah = mysqli_real_escape_string($conn,$_POST['Tarikh_akad_nikah']);
$total = mysqli_real_escape_string($conn,$_POST['total']);
$Deposit = mysqli_real_escape_string($conn,$_POST['Deposit']);
$Balance = mysqli_real_escape_string($conn,$_POST['Balance']);
$Receipt_no = mysqli_real_escape_string($conn,$_POST['Receipt_no']);
$sql = "INSERT INTO mockup_check (Order_date, Confirm_Design_Date, Due_Date, Name, Type_of_Customer, phone, Email, pic, design, Output, Finishing, Submit_date, Product, Size, Material, Type_finishing,
Kuantiti, Artwork, Pengantin_P, Pengantin_L, Jum_Hantaran, Bank_pilihan, Nama_singkatan, Tarikh_akad_nikah, total, Deposit, Balance, Receipt_no)
VALUES
('$Order_date','$Confirm_Design_Date','$Due_Date','$Name','$Type_of_Customer','$phone','$Email','$pic','$design','$Output','$Finishing','$Submit_date','$Product','$Size','$Material','$Type_finishing','$Kuantiti','$Artwork','$Pengantin_P','$Pengantin_L','$Jum_Hantaran','$Bank_pilihan','$Nama_singkatan','$Tarikh_akad_nikah','$total','$Deposit','$Balance','$Receipt_no')";
$result = mysqli_query($conn,$sql);
}
html代码和php脚本。已设置成功表格,但艺术品数据库 没有插入
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("input[name='Artwork']").click(function(){
var value = $('input[name=Artwork]:checked').val();
if(value === 'Other'){
$('#div_ifOther').show();
}
else if(value !== 'Other'){
$('#div_ifOther').hide();
}
});
});
</script>
<div id="div_id_select" class="form-group required">
<label for="id_Artwork" class="control-label col-md-4 requiredField"> Artwork :<span class="asteriskField">*</span> </label>
<div class="controls col-md-9 " style="margin-bottom: 10px">
<label class="radio-inline"><input type="radio" checked="checked" name="Artwork" id="ifUsb" value="Usb" style="margin-bottom: 10px">Usb</label>
<label class="radio-inline"> <input type="radio" name="Artwork" id="ifEmail" value="Email" style="margin-bottom: 10px">Email </label>
<label class="radio-inline"> <input type="radio" id="ifOther" name ="Artwork" value="Other" style="margin-bottom: 10px">Other</label>
</div>
<div id="div_ifOther" class="controls col-md-8 " style="display:none;">
<input class="input-md textinput textInput form-control" maxlength="30" name="Artwork" placeholder="Other" style="margin-bottom: 10px" type="text" />
</div>
答案 0 :(得分:1)
更改输入的name
属性,它应该可以工作。
由于单选按钮和输入name
属性为Artwork
。表单采用最后一个形式,因此仅发送输入值。
<div id="div_id_select" class="form-group required">
<label for="id_Artwork" class="control-label col-md-4 requiredField"> Artwork :<span class="asteriskField">*</span> </label>
<div class="controls col-md-9 " style="margin-bottom: 10px">
<label class="radio-inline"><input type="radio" checked="checked" name="Artwork" id="ifUsb" value="Usb" style="margin-bottom: 10px">Usb</label>
<label class="radio-inline"> <input type="radio" name="Artwork" id="ifEmail" value="Email" style="margin-bottom: 10px">Email </label>
<label class="radio-inline"> <input type="radio" id="ifOther" name ="Artwork" value="Other" style="margin-bottom: 10px">Other</label>
</div>
<div id="div_ifOther" class="controls col-md-8 " style="display:none;">
<input class="input-md textinput textInput form-control" maxlength="30" name="artwork_text" placeholder="Other" style="margin-bottom: 10px" type="text" />
</div>