我有一个带有jquery脚本的数据输入表单,用于将数据插入到mysql数据库中 在表单中,我希望用户在输入框tldno中输入任何值之前先检查其中一个单选按钮。我尝试通过将模糊事件绑定到tldno来检查单选按钮的状态。但问题是,一旦触发模糊事件,就不允许点击单选按钮。如何有效实施。
这是表格
<form id="personnel_data">
<fieldset >
<legend> Personnel Data</legend>
<label for "kgsunit">Select KGS Unit </label><input name="unit" type="radio" value="1" <?php if($user_unit=='1'){echo 'checked="checked" ';}?>/> 1&2 <input name="unit" type="radio" value="3" <?php if($user_unit=='3'){echo 'checked="checked" ';}?> /> 3&4 <input name="unit" type="radio" value="6" <?php if($user_unit=='6'){echo 'checked="checked" ';}?> /> 5&6<br/>
<label for "tld">TLD No. </label>
<input type="text" id="tldno" name="tldno" size="25" maxlength="25" onkeydown="if(event.keyCode==13) event.keyCode=9;"/><br/>
<label for "fname">Full Name</label><input type="text" id="fname" name="fname" size=30 maxlength=30onKeyDown="if(event.keyCode==13) event.keycode=9;"/><br/>
<label for "dob">Date of Birth</label><input type="text" id="datepicker" name="datepicker" /><input type="hidden" id="stddate" name="stddate" value="<?php echo $dateus; //echo date('d-m-Y'); ?>"/><br/>
<label for "cat"> Category</label><input name="cat" type="radio" value="R" />
Regular
<input type="radio" name="cat" value="C" checked="checked"/>Casual<br/>
<div id="emp"><br/><label for "ccno">CC No.</label><input type="text" name="ccno" id="ccno" value="0" size=25 maxlength=25 onkeydown="if(event.keyCode==13) event.keyCode=9;"/><br/>
<label for "empno">Employee No.</label><input type="text" name="empno" id="empno" value="0" size=25 maxlength=25 onkeydown="if(event.keyCode==13) event.keyCode=9;"/></div><br/>
<label for "section">Section</label><select name="section" id="section">
<?php
$db=mysql_select_db($database_met,$met) or die("could not connect");
$secsql= "SELECT *
FROM sections
ORDER BY secname;
";
$result_sec=@mysql_query($secsql) or die(mysql_error());
echo'<option value="" selected="selected">Select Section</option>';
while($row2=mysql_fetch_array($result_sec))
{ echo($row2['secname']);
echo"<option>".$row2['secname']."</option>";}
?>
</select>
<label for "height"> Height in cm</label><input type="text" name="height" value="0" size=25 maxlength=25 onkeydown="if(event.keyCode==13) event.keyCode=9;"/></td>
<input id="submit" type="submit" name="submit" value="Add record" /></td>
</form>
jquery part
jQuery("#tldno").blur(function(){
var rep_sel=jQuery("[name='unit']:checked").val();
if(typeof rep_sel === "undefined"){
alert ('Please Select a Unit First');
jQuery("#tldno").val("");
jQuery('#tldno').focus();
}
else{
var name = rep_sel.concat(jQuery("#tldno").val());
jQuery.post("tld_search_hpu.php", {"name":name}, function(data) {
if (data.msg=="Y"){
alert("Data Exists");
jQuery('#submit').hide();
jQuery('#tldno').focus();
}
else {
jQuery('#submit').show();
}
});
}
});
答案 0 :(得分:0)
我不知道你想要什么,但你可以试试这个:
$(function(){
var status=false;
$('#tldno').focus(function(){
if($('#personnel_data input[name="unit"]:checked').length == 0){
$('#personnel_data input[name="unit"]').eq(0).focus();
status = false;
}else{
status=true;
}
});
$('#tldno').keyup(function(){
if(status){
console.log('do your ajax here')
}
})
});