Ich machte eine Schaltfläche innerhalb einer while-Schleife und dann eine jquery-Funktion übergeben. Jetzt funktioniert die jquery-Funktion auf der ersten Schaltfläche, funktioniert aber nicht auf anderen Schaltflächen.jQuery Funktion nicht mehrere Male durch PHP-Schleife aufrufen
<script>
$(document).ready(function() {
$("#myBtn").click(function() {
var id = this.value;
$("#myModal").modal();
$("#employee").change(function() {
var eid = this.value;
var dataString = 'id=' + id + '&eid=' + eid;
$.ajax({
type: "POST",
url: "ajax.php",
data: dataString,
success: function(result) {
}
});
});
});
});
/* $(document).ready(function(){
$("#myBtn").click(function(){
var id = this.value;
if(id == true){alert(id++);}
});
});*/
</script>
<div>
<div class="panel">
<table id="basicTable" class="table table-striped table-bordered responsive">
<thead class="">
<tr>
<th>S.No</th>
<th>Title</th>
<th>Lead Type</th>
<th>Customer Name</th>
<th>Customer Phone No.</th>
<th>Customer Email</th>
<th>Property Type</th>
<th>Property Location</th>
<th>Active</th>
<th>Edit</th>
<th>Assign</th>
</tr>
</thead>
<tbody>
<?php
$que=mysqli_query($con,"select * from lms_table");
$number=1;
while ($res=mysqli_fetch_array($que))
{
$id=$res['lead_id'];
$pt=$res['required_property_type'];
?>
<tr>
<td align="center"><?php echo $number; ?></td>
<td align="center"><a href="comment.php?id=<?php echo $id; ?>"><?php echo $res['title']; ?></a></td>
<td align="center"><?php echo $res['lead_type']; ?></td>
<td align="center"><?php echo $res['customer_name']; ?></td>
<td align="center"><?php echo $res['customer_no']; ?></td>
<td align="center"><?php echo $res['customer_email']; ?></td>
<?php $qe=mysqli_query($con,"SELECT * FROM `add_property_type` WHERE property_id='$pt'");
$re=mysqli_fetch_array($qe); ?>
<!-- <td align="center"><?php// echo $re['property_type']; ?></td>-->
<td align="center"><?php echo $res['required_property_type']; ?>
<td align="center"><?php echo $res['property_required_location']; ?></td>
<?php
if($res['lead_status']==1){
?>
<td align="center"> <a class="tooltips" data-toggle="tooltip" title="Active" href="lead-active.php?l_id='<?php echo $id; ?>'&id=2"><i class="fa fa-user text-success"></i></a></td>
<?php
} else{
?>
<td align="center"> <a class="tooltips" data-toggle="tooltip" title="Inactive" href="lead-active.php?l_id='<?php echo $id; ?>'&id=1"><i class="fa fa-user text-danger"></i></a></td>
<?php } ?>
<td align="center"><a href="update-lms-table.php?id=<?php echo $id; ?>"><i class="fa fa-edit"></i></a></td>
<td align="center"> <button type="button" class="btn btn-default " name ='but' id="myBtn" value="<?php echo $id['lead_id']; ?>" onclick='get_id(this.value)'>Assign</button> </td>
</tr>
<?php
$number++;
}
?>
</tbody>
</table>
</div>
<!-- panel -->
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" ?role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" style="padding:35px 50px;">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">Assign Employee</h4>
</div>
<div class="modal-body" style="padding:40px 50px;">
<form action="half.php">
<select class="form-control select1 " id="employee">
<option selected value="">Select Employee</option>
<?php
$que1 =mysqli_query($con,"select * from add_employee");
while($r=mysqli_fetch_array($que1)){
$empid=$r['employee_code'];
echo "<option value='$empid' onchange='get_id(this.value)'>".$r['employee_first_name']."</option>";
}
?>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success btn-default" data-dismiss="modal" ><span class="glyphicon glyphicon-off"></span> Login</button>
<button type="submit" class="btn btn-danger btn-default pull-right" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Cancel</button>
</form>
</div>
</div>
</div>
</div>
</div>
Dies sind der Code verwendet. Bitte werfen Sie etwas Licht.
Reinigen Sie Ihren Code –
IDs müssen ** einzigartig ** sein – Andreas
Sie können einen Namen als ID haben, müssen Sie Klasse verwenden, wenn Sie mehrere Schaltflächen haben und Onclick-Ereignis auf denen möchten. –