10/10/2018, 11:08
Hiện thông báo khi người dùng nhấn nút xóa
<script language="javascript">
function check_register()
// kiem tra cac textbox
</script>
<form id="a" name="a" method="post" action="" onsubmit="return check_register();">
<input name="them" type="submit" id="dongy" value="Them" >
<input name="sua" type="submit" id="sua" value="Sua" >
<input name="them" type="submit" id="xoa" value="Xoa" onclick="return confirm('Ban co chac la muon xoa du lieu');" >
Với đoạn code này thì chương trình sẽ hiển thị thông báo "bạn có chắc muốn xóa không" trước, mình muốn khi click nút xóa thì chương trình phải kiểm tra các textbox trước, các bạn giúp mình với.
function check_register()
// kiem tra cac textbox
</script>
<form id="a" name="a" method="post" action="" onsubmit="return check_register();">
<input name="them" type="submit" id="dongy" value="Them" >
<input name="sua" type="submit" id="sua" value="Sua" >
<input name="them" type="submit" id="xoa" value="Xoa" onclick="return confirm('Ban co chac la muon xoa du lieu');" >
Với đoạn code này thì chương trình sẽ hiển thị thông báo "bạn có chắc muốn xóa không" trước, mình muốn khi click nút xóa thì chương trình phải kiểm tra các textbox trước, các bạn giúp mình với.
Bài liên quan





<script type="text/javascript"> function CheckForm(){ if(frmTest.Text.value == '') { confirm("Hay nhap thong tin"); frmTest.Text.focus(); return false; } else { r = confirm("Ban co muon xoa khong?"); if(r == false) return false; else return true; } } </script> <form name="frmTest" method="post" action="" onsubmit="if(CheckForm() == false) return false"> <input type="text" name="Text" value=""/> <input type="submit" name="Xoa" value="Xoa"/> </form><script type="text/javascript"> var form = { addItem: function () { //do something }, editItem: function () { //do something }, deleteItem: function () { $('#form').submit(){ var val = $('#inputs').val(); if(val=='') { $('#inputs').focus(); return false; } if(confirm('Are you sure delete this item?')) { //do something } return false; } } }; </script> <form id="form"> <input type="text" name="item" value=""/> <input type="submit" value="Add" onclick="form.addItem()"/> <input type="submit" value="Edit" onclick="form.editItem()"/> <input type="submit" value="Delete" onclick="form.deleteItem()"/> </form>Code trên xài biến form, bị trùng với biến đặc biệt, phải chuyển thành formAction nó mới hoạt động.
<html> <head> </head> <body> <script type="text/javascript"> var formAction = { addItem: function () { var item = document.getElementById("inputs"); alert('Do Add:' + item.value); }, editItem: function () { var item = document.getElementById("inputs"); alert('Do Edit:' + item.value); }, deleteItem: function () { var item = document.getElementById("inputs"); if(item.value == '') { item.focus(); } else { if (confirm('Are you sure delete this item?')) { //do delete. alert('Deleted' + item.value); item.form.submit(); } } } }; </script> <form id="form" action="" method="post"> <input type="text" id="inputs" value=""/> <input type="button" value="Add" onclick="formAction.addItem();"/> <input type="button" value="Edit" onclick="formAction.editItem();"/> <input type="button" value="Delete" onclick="formAction.deleteItem();"/> </form> </body> </html>