จะส่งค่า ID ไปหา modal ค่ะ ผ่าน button ทำอย่างไรค่ะ แนะนำหน่อยค่ะ
ไม่ยุ่งกะ Code นะครับ ใช้คีย์ว่า "value to modal jquery" อ่าน ประมาณ 3 เว็บแรกก็ได้คำตอบครับ แล้วก็ดูว่าจะจับมาประยุกต์กลับ code เราตรงไหน
Date :
2016-07-07 08:10:22
By :
apisitp
Code (PHP)
<button data-toggle = "modal" data-target="#editemployee" style ="border: 2px solid #8B7355; height: 30px;width: 50px; background-color: #8FBC8F; padding: 5px;" data-id="<?php echo $obResult["EmpID"];?>">
<div class="modal fade" id="editemployee" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Test ID</h4>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="recipient-name" class="control-label">ID:</label>
<input type="text" class="form-control" data-id="emp_id">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</div>
jQuery
Code (JavaScript)
$('#editemployee').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget)
var id= button.data('id')
var modal = $(this)
modal.find('#emp_id').val(id)
})
Date :
2016-07-07 08:20:41
By :
fossil31
ไม่ได้ค่ะ ค่าที่ส่งไปไม่แสดงค่ะ
Date :
2016-07-07 12:01:57
By :
tan_zeeza
Code (PHP)
<!doctype html>
<html lang="en">
<head>
<title>calculate number</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
body{margin-top:40px;}
</style>
<div class="container">
<button data-toggle = "modal" data-target="#editemployee" data-id="1">ID:1</button>
<button data-toggle = "modal" data-target="#editemployee" data-id="2">ID:2</button>
</div>
<div class="modal fade" id="editemployee" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Test ID</h4>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="recipient-name" class="control-label">ID:</label>
<input type="text" class="form-control" id="emp_id">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#editemployee').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
var id= button.data('id');
var modal = $(this);
modal.find('#emp_id').val(id);
});
});
</script>
</body>
</html>
Date :
2016-07-07 12:54:56
By :
fossil31
แก้
<input type="text" class="form-control" data-id="emp_id">
เป็น
<input type="text" class="form-control" id="emp_id">
Date :
2016-07-07 12:55:40
By :
fossil31
ประวัติการแก้ไข 2016-07-09 09:34:42
Date :
2016-07-07 16:12:28
By :
tan_zeeza
Load balance : Server 02