我是使用Twitter bootstrap的新手......我在模态中创建了一个编辑数据表单。这是包含操作编辑和删除的表格代码:
<table class="table table-striped">
<thead>
<tr>
<th class="text-center">No.</th>
<th class="text-center">Nama User</th>
<th class="text-center">Nomor Polisi</th>
<th class="text-center">No Telp GPS</th>
<th class="text-center">No Telp Author</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<?php
$nomor = 0;
while($data=mysql_fetch_array($hasil))
{
$nomor++;
echo"<tr>";
echo"<td><center>".$nomor."</center></td>";
echo"<td>".$data['nama_user']."</td>";
echo"<td>".$data['no_polisi']."</td>";
echo"<td>".$data['no_telp_gps']."</td>";
echo"<td>".$data['no_telp_author']."</td>";?>
<td class="text-center"><a data-toggle="modal" data-target="#modal-edit-gps"
data-id="<?php echo $data['id_gps']?>" data-nama="<?php echo $data['nama_user']; ?>"
data-nomorpolisi="<?php echo $data['no_polisi']; ?>" data-telepongps="<?php echo $data['no_telp_gps']; ?>"
data-teleponauthor="<?php echo $data['no_telp_author']; ?>" class="gps-edit">
<i class=" glyphicon glyphicon-edit"></i></a>    <a onclick="return confirm('anda yakin ingin menghapus data tersebut?? ');" href="../controller/delete_gps.php?id_gps=<?php echo $data['id_gps'] ?>"><i class="glyphicon glyphicon-remove"></i></a></td>
<?php echo"</tr>";
}
?>
</tbody>
</table>
然后这是模态代码中的编辑数据表单:
<div class="modal fade" id="modal-edit-gps" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel"><b>Form Edit Data GPS</b></h4>
</div>
<div class="modal-body">
<form name="edit_user" method="POST" action="../controller/edit_user.php?">
<div class="controls control-group">
<input class="form-control" type="text" name="id_user" id="id_gps" placeholder="ID_user" readonly><br>
<span class="nama_user"></span>
<select name="gps" style="width:555px">
<option value=0 >- Silahkan Pilih User GPS Tracker -</option>
<?php
include"../controller/koneksi.php";
$query=mysql_query("SELECT nama_user FROM tb_user");
while($row = mysql_fetch_array($query))
{
echo"<option value=$row[id_user]>$row[nama_user]</option>";
/*if($row[id_user]==)
{
echo"selected='selected'";
}*/
}
?>
</select>
<br><br><input class="form-control" type="text" name="no_polisi" id="no_polisi" placeholder=" Nomor Polisi Kendaraan">
<br><input class="form-control" type="text" name="no_telp_gps" id="no_telp_gps" placeholder=" nomor telepon GPS">
<br><input class="form-control" type="text" name="no_telp_author" id="no_telp_author" placeholder="Nomor Telepon Author GPS">
</div>
<div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal">Batal</button>
<input type="submit" name="sumbit" value="Simpan" class="btn btn-primary">
</div>
</form>
</div>
<!--<div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal">Batal</button>
<input type="submit" class="btn btn-primary" type="submit" name="submit" value="Simpan">
</div>-->
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
我的目标是使用已编辑数据的现有值填充表单。所以我决定使用javascript发送变量的值来填充表单。这是javascript代码..
<script type="text/javascript">
$(document).on("click", ".gps-edit", function () {
var Myid_gps= $(this).data('id');
$(".modal-body #id_gps").val( Myid_gps );
$(".modal-body #nama_user").val( $(this).data('nama') );
$('span.user-id').text($(this).data('nama'));
$(".modal-body #no_polisi").val( $(this).data('nomorpolisi') );
$(".modal-body #no_telp_gps").val( $(this).data('telepongps') );
$(".modal-body #no_telp_author").val( $(this).data('teleponauthor') );
});
$(document).ready(function()
{
$('.combobox').combobox();
});
</script>
除了组合框之外,一切都按照我的目标进行。我希望将“nama_user”的值插入到可修改的中,所以我可以添加If条件来决定应该选择哪个组合框的值。任何人都可以帮助我吗?
P.S:抱歉复杂的解释和糟糕的英语......