I have a hyperlink 'Add item' wherein once it's clicked it will execute the script below:
<script type="text/javascript">
var selectedId = $("#combobox").val().toString();
var itemId = $("#itemId").val().toString();
var qty = $("#itemQty").val().toString();
//var item =
function addItem() {
$.ajax({
url: "PO_Items.php",
data: "supplier="+$("#combobox").val().toString()+"&Item="+$("#itemId").val().toString()+"&Qty="+$("#itemQty").val().toString(),
cache: false,
success: function(html){
$("#items").empty();
$("#items").append(html);
$("#itemName").val("");
$("#itemId").val("");
$("#itemQty").val("");
}
});
}
Here's is the php code that gets executed:
<?php
include 'config.php';
session_start();
$SessionId = session_id();
$Id = $_GET["PurchaseItemID"];
$delete = "Delete from tbl_purchaseitem Where PurchaseItemID = '$Id'";
$result1 = mysql_query($delete);
$GetItems = "Select * From tbl_purchaseitem Where SessionID = '$SessionId'";
$result2 = mysql_query($GetItems);
echo "<table>";
echo "<th>SessionID</th>";
echo "<th>ItemsId</th>";
echo "<th>Qty</th>";
while($row = mysql_fetch_array($result2))
{
$PurchaseItemId = $row['PurchaseItemID'];
$SessionId = $row['SessionID'];
$ItemsId = $row['ItemsId'];
$Qty = $row['Qty'];
echo "<tr> <td>" .$SessionId ."</td>" ."<td>" .$ItemsId ."</td>" ."<td>" .$Qty ."</td>"
."<td>" ."<a href='#edititem' class='inline2' id='$PurchaseItemId' >Edit item</a>"
."<td>" ." <a href='' id='$PurchaseItemId'>Delete item</a>"
."</tr>";
//<a href="#additem" class="inline" style="display:none" >Add item</a>
}
echo "</table>";
?>
Here another code that I have right now that makes the dynamically added 'Edit item' link open a fancybox:
<script type="text/javascript">
$(".inline2").live("click", function() {
$(this).fancybox({
'titlePosition' : 'inside',
'transitionIn' : 'none',
'transitionOut' : 'none'
});
});
</script>
What's wrong with this is the fancybox will only open on the 2nd click, during the 1st click nothing will happen except that #edititem will be added on the url, My assumption/guess is that it only opens after the 2nd click is because of the .live("click", function(), I've also read that instead of using live() I should use on() because it's already deprecated.
Sir/Ma'am your answers would be of great help and be very much appreciated. Thank you++