Issue 1 = I have the following script:
$(document).ready(function(){
$(".form-inline").on("submit",function(event){
event.preventDefault();
$.ajax({
type: "POST",
url: "php/additem.php",
data: {
itemName: $("#itemName").val(),
pricetotal: $("#price").val(),
description: $("#description").val(),
qty: $("qtyitem"]").val()
},
success: function(data)
{
alert(data);
}
});
});
});
This however does not work since the items this script has to attach to do not show until a specific ajax request occurs. So i need a method to be able to attach properly, here is what i tried (this is in my php file):
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$price ="";
if ($_SESSION['customer_band'] == 'A') {
$price = $row['bandA'];
}
else if ($_SESSION['customer_band'] == 'B') {
$price = $row['bandB'];
}
else if ($_SESSION['customer_band'] == 'C') {
$price = $row['bandC'];
}
else if ($_SESSION['customer_band'] == 'D') {
$price = $row['bandD'];
}
else if ($_SESSION['customer_band'] == 'E') {
$price = $row['bandE'];
}
$data['result_2'] .= '
<div class="col-sm-4 col-md-4">
<div class="content-boxes style-two top-column clearfix animated flipInY" style="opacity: 1;">
<div class="content-boxes-text">
<form action="php/additem.php" method="post" class="form-inline pull-right">
<h4>'.$row['itemName'].'</h4><input id="itemName" type="hidden" name="itemName" value="'.$row['itemName'].'">
<h3>$'.$price.'</h3><input id="price" type="hidden" name="pricetotal" value="'.$price.'">
<img src="../wholesale/img/sourdough.jpg" class="img-reponsive">
<p>'.$row['description'].'</p><input id="description" type="hidden" name="description" value="'.$row['description'].'">
<div class="form-group">
<label class="sr-only" for="qtyitem">Qty</label>
<div class="input-group">
<input type="number" name="qty" class="form-control" id="qtyitem" placeholder="How Many?">
</div>
</div>
<button type="submit" id="additem" class="btn btn-primary">Add</button>
</form>
</div>
<!-- //.content-boxes-text -->
</div>
<!-- //.content-boxes -->
</div>
<script type="text/javascript">
$(document).ready(function(){
$(".form-inline").on("submit",function(event){
event.preventDefault();
$.ajax({
type: "POST",
url: "php/additem.php",
data: {
itemName: $("#itemName").val(),
pricetotal: $("#price").val(),
description: $("#description").val(),
qty: $("#qtyitem").val()
},
success: function(data)
{
alert(data);
}
});
});
});
</script>
';
}
}
Even though this works, this then runs to many times. I need to place this code somwhere outside this while statement.
My second problem is that QTY alerts back as nothing. When i do this query without ajax the QTY works. So i am presuming something is relating to how i am selecting the input inside the ajax script?
Thanks Guys