Currently, I am troubleshooting a website that was created by another developer. There is a form with JavaScript validation to ensure data is accurately entered into the database. However, I am puzzled as to why I keep receiving these alert messages. Please refer to the code snippet below:
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(); ?>";
});
}
}
It seems like the script checks for empty fields before submitting the form. Even when all the fields are filled out correctly, I still encounter alerts such as ('Full name is required').
I appreciate any assistance you can provide.
Additionally, here is the HTML code for reference:
<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>
...
</noscript><br />
...
</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>