|
|
|
ต้องการล็อก textbox โดยการคืนค่าจากคิวรี่ข้อมูลในฐานข้อมูลค่ะ |
|
|
|
|
|
|
|
ตัวอย่าง
Code (PHP)
<?php
///////////////////////////////////////// เริ่มต้น code php ////////////////////////////////////
function is_student($id){
$db=new mysqli('localhost', 'test', 'test', 'test');
$rs=$db->query('select id from tb_member where id='.intval($id));
return $rs->num_rows;
}
if(isset($_REQUEST['id'])){
echo json_encode(array('type'=>is_student($_REQUEST['id'])? 'Duplicate Student ID' : 'FreeID' ));
exit;
}
if(isset($_REQUEST['run'])){
$db=new mysqli('localhost', 'test', 'test', 'test');
foreach($_REQUEST['std_id'] as $key=>$vl){
$id=intval($vl);
$pref=intval($_REQUEST['pref'][$key]);
$nm=$db->real_escape_string($_REQUEST['nm'][$key]);
$sur=$db->real_escape_string($_REQUEST['sur'][$key]);
$db->query("insert into tb_member set id=$id, std_pref=$pref, std_nm='$nm', std_surname='$sur' ");
}
exit;
}
/////////////////////////////////// สิ้นสุด code php /////////////////////////////////////////////////
?><!doctype html>
<html>
<head>
<meta charset="utf8" />
<title>TEST</title>
<!-- ================ เริ่มต้น javascript ==================== -->
<script src="/jquery-2.1.1.min.js"></script>
<script>
$(document).ready(function(){
$('#myTable').delegate('.del', 'click', function(e) {
var ro=$(this).parent().parent();
if(confirm('delete '+ro.attr('id'))){
$(ro).remove(); $('#myTable tr').each(function(index, ele){ $(ele).attr('id', 'tr_'+(index+1)); });
}
}).on('change', '.std_id', function(e){
var tr = $(this).parent().parent();
var vl = $(this).val();
if(vl.length==14){ var ro=$(this).parent().parent();
$.ajax({ url: '?id='+$(this).val()}).done(function(js_txt){
var rs=JSON.parse(js_txt); alert(rs.type);
$(tr).find('.xd').prop('disabled', rs.type!=='FreeID');
});
}else alert('ID must have 14 digits');
}).delegate('.std_id','keypress', function(e){
var charCode = e.which; if (charCode <= 13) return true;
var keyChar = String.fromCharCode(charCode); return (/[0-9\-]/).test(keyChar);
}); // ตรวจสอบ row
$('#AddRow').click(function(e){
var tr_id='tr_'+($('#myTable tr').length+1);
$("#myTable").append( $('#temp_tb tr:last').clone() ).find('tr:last').attr('id', tr_id);
});
$('#save').click(function(e){ document.dataFRM.submit(); });
});
</script>
<!-- ================ สิ้นสุด javascript ==================== -->
</head>
<body>
<form method="post" name="dataFRM" action="?run=submit">
<table border=1 id="myTable"></table>
<button type="button" id="AddRow" >AddRow</button><button id="save" type="button">Save</button>
</form>
<div style="display: none">
<table id="temp_tb" >
<tr>
<td><button type="button" class="del" style="color: red; font-weight: bold;" >x</button></td>
<td><input class="std_id" name="std_id[]" maxlength="14" placeholder="รหัสนักศึกษา" required ></td>
<td><select name="pref[]" disabled class="xd" >
<option value="1">นาย</option>
<option value="2">น.ส.</option>
<option value="3">นาง</option>
</select></td>
<td><input name="nm[]" placeholder="ชื่อ" required disabled class="xd" ></td>
<td><input name="sur[]" placeholder="นามสกุล" required disabled class="xd" ></td>
</tr>
</table>
</div>
</body>
</html>
|
|
|
|
|
Date :
2015-09-14 15:33:37 |
By :
NewbiePHP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thank you ka :)
|
|
|
|
|
Date :
2015-09-15 15:38:01 |
By :
ipchully |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|