function doSaveCustomer(){
if (sendReq.readyState == 4 || sendReq.readyState == 0) {
sendReq.open("POST", 'save_data.php', true);
sendReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
sendReq.onreadystatechange =function() {
if (sendReq.readyState == 4 && sendReq.status == 200) {
//upload gambar
document.getElementById('form1').submit();
}
}
var param = 'email=' + document.getElementById('email').value;
param += '&fname=' + document.getElementById('fname').value;
param += '&lname=' + document.getElementById('lname').value;
param += '&address=' + document.getElementById('address').value;
param += '&gender=' + document.getElementById('gender').value;
sendReq.send(param);
document.getElementById(_documentid).innerHTML = 'Loading....';
document.getElementById('email').value='';
document.getElementById('fname').value='';
document.getElementById('lname').value='';
document.getElementById('address').value='';
}
}
<form action="" method="post" name="form">
<input name="txtNama" type="text">
<input name="btnSave" type="button" value="Save" onClick="SimpanNama(); return false;">
<input name="" type="submit" value="Save" onClick="SimpanNama(); return false;">
</form>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
function SimpanNama(){
$("#loading").html('loading...');
$.post('CobaInput.php', $("form").serialize(){
});
}
</script>
cara nangkap txtNama di CobaInput.php bener gini pa bkn?$Nama = $_POST['txtNama'];
function simpanNama(){
$("#loading").html('loading...');
$.post('CobaInput.php', $("form").serialize(), function(response){
$("#loading").html(response);
});
}
lebih jelasnya lihat documentasi jquery ajax di http://api.jquery.com/jQuery.post/.//untuk textbox kode yang attribute name="txtKode[]"
$kode = $_POST['txtKode'];
//variable $kode akan berupa array
//untuk menyimpan gunakan perulangan
foreach($kode as $kd){
//simpa data satu per satu
}
penjelesan tentang penamaan input field ada di http://ask.myphptutorials.com/questions/view/203#answer-755 if(document.getElementById('txtKode_id').value=="")
{
alert("Kode Harus Di Isi !");
document.getElementById('txtKode_id').focus();
}
else if(document.getElementById('txtNama_id').value=="")
{
alert("Nama Barang Harus di Isi !");
document.getElementById('txtNama_id').focus();
}
else if(document.getElementById('txtMerk_id').value=="")
{
alert("Merk Harus di Isi !");
document.getElementById('txtMerk_id').focus();
}
else if(document.getElementById('txtSatuan_id').value=="")
{
alert("Satuan Harus di Isi !");
document.getElementById('txtSatuan_id').focus();
}
else
....
window.location.href='TabelSukucadang.php';
function validate(){
var valid = true;
$("input").each(function(){
if($(this).val() == ''){
valid = false;
$(this).css('border','1px solid red').parent().append('<span style="color:red">value is required, cannot be empty</span>');
}
});
$("select").each(function(){
if($(this).val() == ''){
valid = false;
$(this).css('border','1px solid red').parent().append('<span style="color:red">value is required, cannot be empty</span>');
}
});
return valid;
}
function simpan(){
var valid = validate();
if(valid){
$("#loading").html('loading...');
$.post('CobaInput.php', $("form").serialize(), function(response){
$("#loading").html(response);
//load (redirect) ke halaman lain
window.location.href='TabelSukucadang.php';
});
}
}