我有maiden name
文本框字段,仅当性别为女性并且用户状态不是单一时才会启用,但只要用户注册了单个状态,就会出现警告,但是仍然保存数据。为什么以及如何删除该警告消息,因为它在消息回显时可见。
我的HTML代码:
<label> Maiden Name</label>
<input type="text" class="form-control" name="maiden" id="mySelect" value="" disabled=true placeholder="Maiden Nname" onKeyPress="return ValidateAlpha(event);" onblur="toUpper(this.value, this.id);" >
<label>Gender</label>
<input type=radio name="gender" id="gender" value='Male'> Male
<input type=radio name="gender" id="gender" value='Female'> Female
<label>Status</label>
<select name="status" id="status" class="form-control">
<option value="Single">Single</option>
<option value="Married">Married</option>
<option value="Widow">Widow</option>
</select>
这是我的javascript:
<script>
//whenever an item with the name attribute set to gender or status is changed:
$(document).on("change", "[name=gender],[name=status]", function(){
//gather the checked gender
var gender = $('[name=gender]:checked').val();
//gather the selected status
var status = $('[name=status] option:selected').val();
//if the user checked female and selected single
if(gender == 'Female' && status != 'Single'){
//enable the maidenname input
$('[name=maiden]').prop('disabled', false);
}
else{
//disable the maidenname input
$('[name=maiden]').prop('disabled', true);
}
});
</script>
我的php
<?php
include('dbcontroller.php');
if(isset($_POST['submit']))
{
$gender = $conn->real_escape_string(trim($_POST['gender']));
$status = $conn->real_escape_string(trim($_POST['status']));
$maiden = $conn->real_escape_string(trim($_POST['maiden']));
$query = "INSERT INTO requests(gender, status, maiden) VALUES('$gender','$status','$maiden')";
} ?>
答案 0 :(得分:0)
如果没有您的代码,很难具体说明,通常您也会发布实际错误,但听起来您需要......
if(empty($_POST['maidenname'])) {$_POST['maidenname'] ='';}