I have a modal containing a textboxes and a table containing some values i want to open the modal and set the values in the textbox from the table so far only the first row is working in setting the values. Any help would be realy great
Here is my code
<?Php
include_once './php/connection.php';
$count = 0;
$sql = "SELECT ID, Name, Profile FROM tbl_employee";
$result = $conn->query($sql);
echo "<table id='employee'>";
echo "<tr>";
echo "<th></th>";
echo "<th>Name</th>";
echo "<th>Profile</th>";
echo "</tr>";
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$count++;
echo "<tr>";
echo "<td><img src='./profiles/".$row['Profile']."' alt='' style='width: 60px; height: 80px;'></td>";
echo "<td><span id='firstname'>".$row['Name']."</td>";
echo "<td>**********</td>";
echo "<td><a href=\"./php/edit.php?id=".$row['ID']."\">Jobs</a></td>";
echo "<td><button type='button' class='btn btn-success edit' value='".$row['ID']."' data-toggle='modal' data-target='#myModal'><span class='glyphicon glyphicon-edit'></span> Edit</button></td>";
echo "<td><a href=\"./php/delete.php?id=".$row['ID']."\" >Delete</a></td>";
echo "</tr>";
}
} else {
}
echo "<h3>(".$count.")</h3>"
?>
Modal Code
<!-- Modal -->
<button type='button' class='close' data-dismiss='modal'>×</button>
<h4 class='modal-title' id='header'>Edit Employee Details</h4>
</div>
<div class='modal-body'>
<form method="POST" action="./php/editjob.php">
<div class="container-fluid">
<div class="form-group input-group">
<span class="input-group-addon" style="width:150px;">Name:</span>
<input type="text" style="width:350px;" class="form-control" id="efirstname" name="efirstname" readonly >
</div>
</div>
<div class="container-fluid">
<div class="form-group input-group">
<span class="input-group-addon" style="width:150px;">New Title:</span>
<input type="text" style="width:350px;" class="form-control" id="qfirstname" name="qfirstname">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" value="submit" class="btn btn-success"><span class="glyphicon glyphicon-edit"></span> </i> Update</button>
</form>
<button type="button" class="btn btn-default" data-dismiss="modal" onclick="ClearFields();">Close</button>
</div>
</div>
</div>
and the javascript here
$(document).ready(function(){
$(document).on('click', '.edit', function(){
var first= $('#firstname').text();// get firstname
$('#efirstname').val(first);
$('#qfirstname').val(first);
});
});