Saturday, December 21, 2013

to prevent submit form and show alert, before completing the form

<script>
String.prototype.toProperCase = function () {
return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
};
function check_kosong(){
els=['input_id_1','input_id_2','input_id_3']
for (var i_tem = 0; i_tem < els.length; i_tem++){
var check=document.getElementById(els[i_tem]).value;
if (check == ''){
var a=els[i_tem];
//replace underscore with space
var b=a.replace(/_/g, ' ');
//show alert with convert text to Proper Case/ Title Case
alert (b.toProperCase() +' belum di isi');
return false;
i_tem=els.length;
}
}
}
</script>
<form onSubmit="return check_kosong();" action="../insert_your_file.php" method="post">
......
......
.......
</form>

No comments:

Post a Comment