Vote count:
0
This case, I want to validate form. First, it will check data in MySql. If there is a same value, validation will appear 'Data Could not be entered '. Validation has run. But, if I click the submit button, it still save data to MySql though data is wrong. So, How could be the data is not stored to mysql before the form fill with correct value. Thanks for help me.
this is my php script.
<form class="form-horizontal" action='upload_data.php' method="POST" enctype="multipart/form-data" name="" id="">
<div class="control-group">
<label class="control-label" for="data">Id Kapal</label>
<div class="controls">
<input type="text" id="id_kapal" name="id_kapal" placeholder="" class="input-xlarge" required autofocus>
<br/>
<span id="availability_status2"></span>
</div>
</div>
<div class="control-group">
<div class="controls">
<button class="btn btn-success" >Submit</button>
</div>
</div>
</form>
this is javascript
<script type="text/javascript">
$(document).ready(function()
{
$("#id_kapal").change(function()
{
var id_kapal = $("#id_kapal").val();
if(id_kapal.length > 3)//if the lenght greater than 3 characters
{
$("#availability_status2").html('<img src="../assets/img/validation/loader.gif" align="absmiddle"> Checking availability...');
$.ajax({
type: "POST",
url: "ajax_check_kapal.php",
data: {id_kapal: id_kapal},
success: function(server_response){
if(server_response == '0')
{
$("#availability_status2").html('<img src="../assets/img/validation/available.png" align="absmiddle"> <font color="Green"> Data Could be entered</font> ');
}
else if(server_response == '1')
{
$("#availability_status2").html('<img src="../assets/img/validation/not_available.png" align="absmiddle"> <font color="red">Data Could not be entered </font>');
}
}
});
}
else
{`enter code here`
$("#availability_status2").html('<font color="#cc0000">short character</font>');
}
return false;
});
});
</script>
asked 20 secs ago
Javascript Validation Save Data to MySql not working
Aucun commentaire:
Enregistrer un commentaire