gpt4 book ai didi

JavaScript 表单验证错误

转载 作者:行者123 更新时间:2023-11-28 09:32:53 25 4
gpt4 key购买 nike

我正在开发一个由另一位程序员开发的网站。有一个表单在将数据输入数据库之前进行 JavaScript 验证。但我真的不明白为什么我会收到此警报。请参阅下面的代码:

function save(){
if (echeck(document.getElementById('email').value)==false){
document.getElementById('email').focus();
}else if(document.getElementById('fullname').value==''){
alert("Full name is required");
document.getElementById('fullname').focus();
}else if(document.getElementById('handphone').value==''){
alert("HP number is required");
document.getElementById('handphone').focus();
}else if(document.getElementById('bank_name').value==''){
alert("Bank Account Name is required");
document.getElementById('bank_name').focus();
}else if(document.getElementById('bank_number').value==''){
alert("Bank Account Number is required");
document.getElementById('bank_number').focus();
}else if(document.getElementById('code').value==''){
alert("Captcha Code cannot be blank");
document.getElementById('code').focus();
}else{
$.post("<?php echo base_url(); ?>index.php/misterjudi/register/", {
email:document.getElementById('email').value,
fullname:document.getElementById('fullname').value,
handphone:document.getElementById('handphone').value,
bank:document.getElementById('bank').value,
bank_name:document.getElementById('bank_name').value,
bank_number:document.getElementById('bank_number').value,
},
function(data){
alert("Successfully registered");
location.href="<?php echo base_url(); ?>";
});
}
}

如果我理解正确的话,它会检查字段是否不为空。即使我填写了所有字段,我仍然收到类似(“需要全名”)的警报。

提前感谢您的帮助。

这是 HTML 代码:

<table style="border:0px solid #CCC; width:100%;">
<tr>
<td style="padding-bottom:10px; width:180px;">Email
<span style="color:#F00;">*</span></td><td style="padding-left:20px; padding-bottom:10px;">
<input id="email" type="text" name="email" onblur="check_email(this.value);" />
</td>
</tr>
<tr>
<td style="padding-bottom:10px;">Nama <span style="color:#F00;">*</span>
</td>
<td style="padding-left:20px; padding-bottom:10px;">
<input id="fullname" type="text" name="fullname" />
</td>
</tr>
<tr>
<td style="padding-bottom:10px;">No HP <span style="color:#F00;">*</span>
</td>
<td style="padding-left:20px; padding-bottom:10px;">
<input id="handphone" type="text" name="handphone" />
</td>
</tr>
<tr>
<td style="padding-bottom:10px;">Nama Bank <span style="color:#F00;">*</span></td>
<td style="padding-left:20px; padding-bottom:10px;">
<select name="bank" id="bank">
<?php $data=$this->dubol_model->get_bank(); ?>
<?php for($i=0;$i<count($data);$i++){ ?>
<option value="<?php echo $data[$i]['BankCode']; ?>">
<?php echo $data[$i]['BankName']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td style="padding-bottom:10px;">Nama Rekening <span style="color:#F00;">*</span></td>
<td style="padding-left:20px; padding-bottom:10px;"><input id="bank_name" type="text" name="bank_account_name" /></td>
</tr>
<tr>
<td style="padding-bottom:10px;">Nomor Rekening <span style="color:#F00;">*</span></td>
<td style="padding-left:20px; padding-bottom:10px;">
<input id="bank_number" type="text" name="bank_account_number" />
</td>
</tr>
<tr>
<td colspan="2">
<div style="width: 430px; padding-top:20px; padding-bottom:20px; float: left; height:90px; background-color:#FFF; border:1px solid #CCC;">
<img id="siimage" align="left" style="padding-right: 5px; border: 0" src="<?php echo base_url(); ?>/captcha/securimage_show.php?sid=<?php echo md5(time()) ?>" />
<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0','width','19','height','19','id','SecurImage_as3','align','middle','src','<?php echo base_url(); ?>/captcha/securimage_play?audio=<?php echo base_url(); ?>/captcha/securimage_play.php&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5','quality','high','bgcolor','#ffffff','name','SecurImage_as3','allowscriptaccess','sameDomain','allowfullscreen','false','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','<?php echo base_url(); ?>/captcha/securimage_play?audio=<?php echo base_url(); ?>/captcha/securimage_play.php&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5' ); //end AC code
</script>
<noscript>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="19" height="19" id="SecurImage_as3" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="<?php echo base_url(); ?>/captcha/securimage_play.swf?audio=<?php echo base_url(); ?>/captcha/securimage_play.php&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="<?php echo base_url(); ?>/captcha/securimage_play.swf?audio=<?php echo base_url(); ?>/captcha/securimage_play.php&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5" quality="high" bgcolor="#ffffff" width="19" height="19" name="SecurImage_as3" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</noscript><br />
<!-- pass a session id to the query string of the script to prevent ie caching -->
<a tabindex="-1" style="border-style: none" href="#" title="Refresh Image" onClick="document.getElementById('siimage').src = '<?php echo base_url(); ?>/captcha/securimage_show.php?sid=' + Math.random(); return false"><img src="<?php echo base_url(); ?>/captcha/images/refresh.gif" alt="Reload Image" border="0" onClick="this.blur()" align="bottom" /></a>
</div>
</td>
</tr>
<tr>
<td style="padding-top:10px;">Code <span style="color:#F00;">*</span></td>
<td style="padding-top:10px;">
<input id="code" type="text" name="code" size="12" />
</td>
</tr>
<tr>
<td colspan="2" style="padding-top:20px;">
<input type="button" value=" Close " onclick="$('#register').animate({ height: 'toggle', opacity: 'toggle'}, 1000);" />
<input type="button" value="Register" onclick="save();" />
</td>
</tr>
</table>

最佳答案

类型:console.log(document.getElementById('fullname').value, document.getElementById('fullname').value === '');在行 'alert("需要全名");' 之前进行调试。

此代码将在您的网络检查器控制台中打印该输入的值以及它是否等于空字符串。我想这会帮助你理解这个问题。

关于JavaScript 表单验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13537612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com