I want to auto compute the remaining stock from inventory by typing in the input type named used. What I want to happen is after I type a number in 'Withdrawn' it should subtract to quantity then show the result to remaining stock. The values came from the database.
Here's what I did but I didn't work I don't know why can you please help me? I am still a beginner btw so correct my code if it looks wrong. Thank you
list.php:
<div class="modal fade" id="updatebtnmodal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Update Used</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<form id="myForm" action="<?php echo base_url().'admin/inventory/updateused/'.$inv['i_id'];?>" method="POST"
class="form-container mx-auto shadow-container" style="width:80%" enctype="multipart/form-data">
<div class="form-group">
<input type="hidden" name="update_id" id="update_id">
<label for="cname">Category</label>
<input type="text" class="form-control my-2
<?php echo (form_error('name') != "") ? 'is-invalid' : '';?>" name="cname" id="cname"
placeholder="Enter Item name" value="<?php echo set_value('cname',$inv['cat_id']); ?>" readonly>
<?php echo form_error('cname'); ?>
<span></span>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="hidden" name="update_id" id="update_id">
<label for="name">Item Name</label>
<input type="text" class="form-control my-2
<?php echo (form_error('name') != "") ? 'is-invalid' : '';?>" name="name" id="name"
placeholder="Enter Item name" value="<?php echo set_value('name'); ?>" readonly>
<?php echo form_error('name'); ?>
<span></span>
</div>
<div class="form-group">
<label for="d_date">Delivered Date</label>
<input type="text" class="form-control my-2
<?php echo (form_error('d_date') != "") ? 'is-invalid' : '';?>" id="d_date" name="d_date"
placeholder="Delivered Date" value="<?php echo set_value('d_date'); ?>"readonly>
<?php echo form_error('d_date'); ?>
<span></span>
</div>
<div class="form-group">
<label for="used">Withdrawn</label>
<input type="number" class="form-control my-2
<?php echo (form_error('used') != "") ? 'is-invalid' : '';?>" id="used" name="used" class="used" onchange="calc()"
placeholder="Enter No. Withdrawn Items" value="<?php echo set_value('used'); ?>">
<?php echo form_error('used'); ?>
<span></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="quantity">Quantity</label>
<input type="number" class="form-control my-2
<?php echo (form_error('quantity') != "") ? 'is-invalid' : '';?>" id="quantity" name="quantity" class="quantity"
placeholder="Enter Quantity" value="<?php echo set_value('quantity'); ?>">
<?php echo form_error('quantity'); ?>
<span></span>
</div>
<div class="form-group">
<label for="exp_date">Expiration Date</label>
<input type="text" class="form-control my-2
<?php echo (form_error('e_date') != "") ? 'is-invalid' : '';?>" id="e_date" name="e_date"
placeholder="Expiration Date" value="<?php echo set_value('e_date'); ?>"readonly>
<?php echo form_error('e_date'); ?>
<span></span>
</div>
<div class="form-group">
<label for="rem_qty">Remaining Stock</label>
<input type="number" class="form-control my-2
<?php echo (form_error('rem_qty') != "") ? 'is-invalid' : '';?>" id="rem_qty" name="rem_qty" class="rem_qty"
placeholder="Enter No. Remaining Stock" >
<?php echo form_error('rem_qty'); ?>
<span></span>
</div>
</div>
</div>
<button type="submit" name="updatedata" class="btn btn-primary ml-2">Make Changes</button>
Back
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Js:
function calc() {
var quantity = document.getElementById("quantity").innerHTML;
var used = document.getElementById("used").value;
var rem_qty = parseFloat(quantity) - used
if (!isNaN(rem_qty))
document.getElementById("rem_qty").innerHTML = rem_qty
}
Try this javascript code
function calc() {
var quantity = document.getElementById("quantity").value;
var used = document.getElementById("used").value;
var rem_qty = 0;
if(quantity >= used){
rem_qty = parseFloat(quantity) - used;
}
if(rem_qty != 0){
document.getElementById("rem_qty").value = rem_qty
}
}
I hope this code will help you out.
Related
I have a form with a series of fields I want to make repeating. I have operational code however when I click on any remove button other than the first my code re-arranges the fields in the row like so:
My code is shown below, I think I'm going wrong with the :first selectors????
<div class="row">
<div class="col-12">
<div id="repeatingTides" class="row">
<div class="col-md-2 col-lg-4 tidePort">
<div class="form-group ">
<label for="tidePort">Tide Port</label>
<input type="text" id="tidePort" name="tidePort[]" class="form-control <?php echo (!empty($data['formData']['tidePort_error'])) ? 'is-invalid' : ''; ?>" value="<?php echo $data['formData']['tidePort']; ?>"/>
<span class="invalid-feedback"><?php echo $data['formData']['tidePort_error']; ?></span>
</div>
</div>
<div class="col-md-5 col-lg-4 tideHW">
<label for="hwTime">HW Time & Height</label>
<div class="input-group ">
<input type="time" id="hwTime" name="hwTime[]" class="form-control <?php echo (!empty($data['formData']['hwTime_error'])) ? 'is-invalid' : ''; ?>" value="<?php echo $data['formData']['hwTime']; ?>"/>
<input type="number" step="0.01" id="hwHeight" name="hwHeight[]" class="form-control <?php echo (!empty($data['formData']['hwHeight_error'])) ? 'is-invalid' : ''; ?>" value="<?php echo $data['formData']['hwHeight']; ?>"/>
<span class="invalid-feedback"><?php echo $data['formData']['hwTime_error']; ?></span>
<span class="invalid-feedback"><?php echo $data['formData']['hwHeight_error']; ?></span>
</div>
</div>
<div class="col-md-5 col-lg-4 tideLW">
<label for="lwTime">LW Time & Height</label>
<div class="input-group ">
<input type="time" id="lwTime" name="lwTime" class="form-control <?php echo (!empty($data['formData']['lwTime_error'])) ? 'is-invalid' : ''; ?>" value="<?php echo $data['formData']['lwTime']; ?>"/>
<input type="number" step="0.01" id="lwHeight" name="lwHeight[]" class="form-control <?php echo (!empty($data['formData']['lwHeight_error'])) ? 'is-invalid' : ''; ?>" value="<?php echo $data['formData']['lwHeight']; ?>"/>
<div class="input-group-append">
<button class="btn btn-ym-success btn-add-tide" type="button"><i class="fas fa-plus text-white"></i></button>
</div>
<span class="invalid-feedback"><?php echo $data['formData']['lwTime_error']; ?></span>
<span class="invalid-feedback"><?php echo $data['formData']['lwHeight_error']; ?></span>
</div>
</div>
</div>
<script>
$(document).ready(function() {
var controlFormTides = $('#repeatingTides:first');
controlFormTides.find('.tideLW:not(:last) .btn-add-tide')
.removeClass('btn-add-tide btn-ym-success').addClass('btn-remove-tide')
.removeClass('btn-ym-success').addClass('btn-ym-danger')
.html('<i class="fas fa-minus text-white"></i>');
});
$(document).on('click', '.btn-add-tide', function(e)
{
e.preventDefault();
var controlFormTides = $('#repeatingTides:first'),
currentTideLW = $(this).parents('.tideLW:first'),
currentTidePort = $('.tidePort:first'),
currentTideHW = $('.tideHW:first'),
newTidePortEntry = $(currentTidePort.clone()).appendTo(controlFormTides);
newTideHWEntry = $(currentTideHW.clone()).appendTo(controlFormTides);
newTideLWEntry = $(currentTideLW.clone()).appendTo(controlFormTides);
controlFormTides.find('.tideLW:not(:last) .btn-add-tide')
.removeClass('btn-add-tide btn-ym-success').addClass('btn-remove-tide')
.removeClass('btn-ym-success').addClass('btn-ym-danger')
.html('<i class="fas fa-minus text-white"></i>');
}).on('click', '.btn-remove-tide', function(e)
{
e.preventDefault();
$('.tideHW:first').remove();
$('.tidePort:first').remove();
$(this).parents('.tideLW:first').remove();
return false;
});
</script>
</div>
</div>
In your current you were adding all divs separately instead you can put all 3 divs i.e : tidePort ,tideHW..etc in some outer div and simply use .clone() to clone that entire div and make change to same cloned div . Then, append this cloned div using $("#repeatingTides").append(controlFormTides) .
Now, to remove the divs you can simply use $(this).parents('.outer').remove(); this will remove entire div which was added.
Demo Code :
$(document).on('click', '.btn-add-tide', function(e) {
e.preventDefault();
//get first div insde repeatingtildes
var controlFormTides = $('#repeatingTides .outer:first').clone(true);
$(controlFormTides).find('button.btn')
.removeClass('btn-add-tide btn-ym-success').addClass('btn-remove-tide btn-ym-danger')
.html('<i class="fa fa-minus"></i>');//add remove class
$("#repeatingTides").append(controlFormTides)
}).on('click', '.btn-remove-tide', function(e) {
e.preventDefault();
$(this).parents('.outer').remove();//remove closest class .outer
return false;
});
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-12">
<div id="repeatingTides">
<!--added this div-->
<div class="outer row">
<div class="col-md-2 col-lg-4 tidePort">
<div class="form-group ">
<label for="tidePort">Tide Port</label>
<input type="text" id="tidePort" name="tidePort[]" class="form-control <?php echo (!empty($data['formData']['tidePort_error'])) ? 'is-invalid' : ''; ?>" value="1" />
<span class="invalid-feedback"></span>
</div>
</div>
<div class="col-md-5 col-lg-4 tideHW">
<label for="hwTime">HW Time & Height</label>
<div class="input-group ">
<input type="time" id="hwTime" name="hwTime[]" class="form-control <?php echo (!empty($data['formData']['hwTime_error'])) ? 'is-invalid' : ''; ?>" value="<?php echo $data['formData']['hwTime']; ?>" />
<input type="number" step="0.01" id="hwHeight" name="hwHeight[]" class="form-control <?php echo (!empty($data['formData']['hwHeight_error'])) ? 'is-invalid' : ''; ?>" value="<?php echo $data['formData']['hwHeight']; ?>" />
<span class="invalid-feedback"><?php echo $data['formData']['hwTime_error']; ?></span>
<span class="invalid-feedback"><?php echo $data['formData']['hwHeight_error']; ?></span>
</div>
</div>
<div class="col-md-5 col-lg-4 tideLW">
<label for="lwTime">LW Time & Height</label>
<div class="input-group ">
<input type="time" id="lwTime" name="lwTime" class="form-control <?php echo (!empty($data['formData']['lwTime_error'])) ? 'is-invalid' : ''; ?>" value="<?php echo $data['formData']['lwTime']; ?>" />
<input type="number" step="0.01" id="lwHeight" name="lwHeight[]" class="form-control <?php echo (!empty($data['formData']['lwHeight_error'])) ? 'is-invalid' : ''; ?>" value="<?php echo $data['formData']['lwHeight']; ?>" />
<div class="input-group-append">
<button class="btn btn-ym-success btn-add-tide" type="button"><i class="fa fa-plus "></i></button>
</div>
<span class="invalid-feedback"><?php echo $data['formData']['lwTime_error']; ?></span>
<span class="invalid-feedback"><?php echo $data['formData']['lwHeight_error']; ?></span>
</div>
</div>
</div>
</div>
i have php code and mysql database and i have one problem, for example i have item with name Subaru with ID 1 and also Ford with ID 2 when i try to add event for Subaru it's not adding value to ID 1 its adding to ID 2(to last ID it can be other.) i want to make like this, when i press button with ID 1 its inserting value to ID 1 and when i select for example ID 5 its adding value to ID 5. There is my php code also my database sql. i think you understand me, My English is not so good...
there is my code and database here
<a href="#out<?php echo $id;?>" data-toggle="modal">
<button type='button' class='btn btn-default btn-sm'><span class='glyphicon glyphicon-minus' aria-hidden='true'></span></button>
</a>
<a href="#add<?php echo $id;?>" data-toggle="modal">
<button type='button' class='btn btn-success btn-sm'><span class='glyphicon glyphicon-plus' aria-hidden='true'></span></button>
</a>
<a href="#edit<?php echo $id;?>" data-toggle="modal">
<button type='button' class='btn btn-warning btn-sm'><span class='glyphicon glyphicon-edit' aria-hidden='true'></span></button>
</a>
<a href="#delete<?php echo $id;?>" data-toggle="modal">
<button type='button' class='btn btn-danger btn-sm'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></button>
</a>
</td>
<!--In Stock/s Modal -->
<div id="add<?php echo $id; ?>" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<form method="post" class="form-horizontal" role="form">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add Stocks</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="control-label col-sm-2" for="item_name">Item Name:</label>
<div class="col-sm-3">
<input type="hidden" name="add_stocks_id" value="<?php echo $id; ?>">
<input type="text" class="form-control" id="item_name" name="item_name" placeholder="Item Name" required readonly value="<?php echo $item_name; ?>"> </div>
<label class="control-label col-sm-2" for="item_code">Item Code:</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="item_code" name="item_code" placeholder="Item Code" required readonly value="<?php echo $item_code; ?>" autocomplete="off"> </div>
<label class="control-label col-sm-1" for="dr_no">DR #:</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="dr_no" name="dr_no" placeholder="DR #" autocomplete="off">
</div>
</div>
<br>
<br>
<div class="form-group">
<label class="control-label col-sm-2" for="item_name">Quantity:</label>
<div class="col-sm-4">
<input type="number" class="form-control" id="quantity" name="quantity" placeholder="Quantity" autocomplete="off" required min="1"> </div>
<label class="control-label col-sm-2" for="item_name">Remarks:</label>
<div class="col-sm-4">
<textarea class="form-control" id="remarks" name="remarks" placeholder="Remarks"></textarea>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="event">Event:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="item_name" name="event" placeholder="Event">
</div>
</div>
<br>
<br>
<br>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" name="add_inventory"><span class="glyphicon glyphicon-plus"></span> Add</button>
<button type="button" class="btn btn-warning" data-dismiss="modal"><span class="glyphicon glyphicon-remove-circle"></span> Cancel</button>
</div>
</form>
</div>
</div>
</div>
<div id="out<?php echo $id; ?>" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<form method="post" class="form-horizontal" role="form">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Out Stocks</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="control-label col-sm-2" for="item_name">Item Name:</label>
<div class="col-sm-2">
<input type="hidden" name="minus_stocks_id" value="<?php echo $id; ?>">
<input type="text" class="form-control" id="item_name" name="item_name" placeholder="Item Name" required readonly value="<?php echo $item_name; ?>"> </div>
<label class="control-label col-sm-2" for="item_code">Item Code:</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="item_code" name="item_code" placeholder="Item Code" required readonly value="<?php echo $item_code; ?>"> </div>
<label class="control-label col-sm-2" for="dr_no">DR No.:</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="dr_no" name="dr_no" placeholder="DR No." autocomplete="off" required autofocus> </div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="item_name">Quantity:</label>
<div class="col-sm-4">
<input type="number" class="form-control" id="quantity" name="quantity" placeholder="Quantity" autocomplete="off" required max="<?php echo $qty; ?>" min="1"> </div>
<label class="control-label col-sm-2" for="received_by" data-toggle="tooltip" title="Unit of Measurement">Receive By:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="received_by" name="received_by" autocomplete="off" required> </div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="item_name">Remarks:</label>
<div class="col-sm-10">
<textarea class="form-control" id="remarks" name="remarks" placeholder="Remarks"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" name="minus_inventory"><span class="glyphicon glyphicon-plus"></span> Out</button>
<button type="button" class="btn btn-warning" data-dismiss="modal"><span class="glyphicon glyphicon-remove-circle"></span> Cancel</button>
</div>
</div>
</form>
</div>
</div>
<div id="changepass" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<form action="" method="post">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Change Password</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="control-label col-sm-2" for="name">Current:</label>
<div class="col-sm-10">
<input type="password" class="form-control" name="current_password" required placeholder="Current Password" autofocus autocomplete="off"> </div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="name">New:</label>
<div class="col-sm-10">
<input type="password" class="form-control" name="new_password" required placeholder="New Password" autocomplete="off"> </div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="name">Repeat:</label>
<div class="col-sm-10">
<input type="password" class="form-control" name="repeat_password" required placeholder="Repeat Password" autocomplete="off"> </div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" name="change_pass">Update</button>
</div>
</div>
</form>
</div>
</div>
</div>
<div id="edit<?php echo $id; ?>" class="modal fade" role="dialog">
<form method="post" class="form-horizontal" role="form">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit Item</h4>
</div>
<div class="modal-body">
<input type="hidden" name="edit_item_id" value="<?php echo $id; ?>">
<div class="form-group">
<label class="control-label col-sm-2" for="item_name">Item Name:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="item_name" name="item_name" value="<?php echo $item_name; ?>" placeholder="Item Name" required autofocus> </div>
<label class="control-label col-sm-2" for="item_code">Item Code:</label>
<div class="col-sm-4">
<input type="text" readonly class="form-control" id="item_code" name="item_code" value="<?php echo $item_code; ?>" placeholder="Item Code" required> </div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="item_description">Description:</label>
<div class="col-sm-4">
<textarea cclass="form-control" id="item_description" name="item_description" placeholder="Description" required style="width: 100%;">
<?php echo $item_description; ?>
</textarea>
</div>
<label class="control-label col-sm-2" for="item_category">Category:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="item_category" name="item_category" value="<?php echo $item_category; ?>" placeholder="Category" required> </div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" name="update_item"><span class="glyphicon glyphicon-edit"></span> Edit</button>
<button type="button" class="btn btn-warning" data-dismiss="modal"><span class="glyphicon glyphicon-remove-circle"></span> Cancel</button>
</div>
</div>
</div>
</form>
</div>
<!--Delete Modal -->
<div id="delete<?php echo $id; ?>" class="modal fade" role="dialog">
<div class="modal-dialog">
<form method="post">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Delete</h4>
</div>
<div class="modal-body">
<input type="hidden" name="delete_id" value="<?php echo $id; ?>">
<div class="alert alert-danger">Are you Sure you want Delete <strong>
<?php echo $item_name; ?>?</strong> </div>
<div class="modal-footer">
<button type="submit" name="delete" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> YES</button>
<button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove-circle"></span> NO</button>
</div>
</div>
</div>
</form>
</div>
</div>
</tr>
<?php
}
if(isset($_POST['change_pass'])){
$sql = "SELECT password FROM tbl_user WHERE username='$session_username'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if($row['password'] != $current_password){
echo "<script>window.alert('Invalid Password');</script>";
$passwordErr = '<div class="alert alert-warning"><strong>Password!</strong> Invalid.</div>';
} elseif($new_password != $repeat_password) {
echo "<script>window.alert('Password Not Match!');</script>";
$passwordErr = '<div class="alert alert-warning"><strong>Password!</strong> Not Match.</div>';
} else{
$sql = "UPDATE tbl_user SET password='$new_password' WHERE username='$session_username'";
if ($conn->query($sql) === TRUE) {
echo "<script>window.alert('Password Successfully Updated');</script>";
} else {
echo "Error updating record: " . $conn->error;
}
}
}
} else {
$usernameErr = '<div class="alert alert-danger"><strong>Username</strong> Not Found.</div>';
$username = "";
}
}
//Update Items
if(isset($_POST['update_item'])){
$edit_item_id = $_POST['edit_item_id'];
$item_name = $_POST['item_name'];
$item_code = $_POST['item_code'];
$item_category = $_POST['item_category'];
$item_description = $_POST['item_description'];
$sql = "UPDATE tbl_garage SET
item_name='$item_name',
item_code='$item_code',
item_category='$item_category',
item_description='$item_description'
WHERE id='$edit_item_id' ";
if ($conn->query($sql) === TRUE) {
echo '<script>window.location.href="inventory.php"</script>';
} else {
echo "Error updating record: " . $conn->error;
}
}
if(isset($_POST['delete'])){
// sql to delete a record
$delete_id = $_POST['delete_id'];
$sql = "DELETE FROM tbl_garage WHERE id='$delete_id' ";
if ($conn->query($sql) === TRUE) {
$sql = "DELETE FROM tbl_inventory WHERE id='$delete_id' ";
if ($conn->query($sql) === TRUE) {
$sql = "DELETE FROM tbl_inventory WHERE id='$delete_id' ";
echo '<script>window.location.href="inventory.php"</script>';
} else {
echo "Error deleting record: " . $conn->error;
}
} else {
echo "Error deleting record: " . $conn->error;
}
}
}
//Add Item
if(isset($_POST['add_item'])){
$item_name = $_POST['item_name'];
$item_code = $_POST['item_code'];
$item_category = $_POST['item_category'];
$item_description = $_POST['item_description'];
$sql = "INSERT INTO tbl_garage (item_name,item_code,item_description,item_category,item_critical_lvl,item_date)VALUES ('$item_name','$item_code','$item_description','$item_category','$item_critical_lvl','$date')";
if ($conn->query($sql) === TRUE) {
$add_inventory_query = "INSERT INTO tbl_inventory(item_name,item_code,date,qty)VALUES ('$item_name','$item_code','$date','0')";
if ($conn->query($add_inventory_query) === TRUE) {
echo '<script>window.location.href="inventory.php"</script>';
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
if(isset($_POST['add_inventory'])){
$add_stocks_id = clean($_POST['add_stocks_id']);
$remarks = clean($_POST["remarks"]);
$quantity = clean($_POST['quantity']);
$event = clean($_POST['event']);
$sql = "INSERT INTO tbl_events(date,item_name,item_code,qty,remarks,event)VALUES ('$date_time','$item_name','$item_code','$quantity','$remarks','$event')";
if ($conn->query($sql) === TRUE) {
$add_inv = "UPDATE tbl_inventory SET qty=(qty + '$quantity') WHERE id='$add_stocks_id' ";
if ($conn->query($add_inv) === TRUE) {
echo '<script>window.location.href="inventory.php"</script>';
} else {
echo "Error updating record: " . $conn->error;
}
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
if(isset($_POST['minus_inventory'])) {
$minus_stocks_id = clean($_POST['minus_stocks_id']);
$remarks = clean($_POST["remarks"]);
$quantity = clean($_POST['quantity']);
$sql = "INSERT INTO tbl_events(date,item_name,item_code,qty, sender_receiver,in_out, remarks)VALUES ('$date_time','$item_name','$item_code','$quantity','$received_by','out','$remarks')";
if ($conn->query($sql) === TRUE) {
$add_inv = "UPDATE tbl_inventory SET qty=(qty - '$quantity') WHERE id='$minus_stocks_id' ";
if ($conn->query($add_inv) === TRUE) {
echo '<script>window.location.href="inventory.php"</script>';
} else {
echo "Error updating record: " . $conn->error;
}
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
?>
</tbody>
</table>
</div>
<!--Add Item Modal -->
<div id="add" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<form method="post" class="form-horizontal" role="form">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add Item</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="control-label col-sm-2" for="item_name">Item Name:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="item_name" name="item_name" placeholder="Item Name" autocomplete="off" autofocus required> </div>
<label class="control-label col-sm-2" for="item_code">Item Code:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="item_code" name="item_code" placeholder="Item Code" autocomplete="off" required> </div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="item_category">Category:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="item_category" name="item_category" placeholder="Item Category" autocomplete="off" required> </div>
<label class="control-label col-sm-2" for="item_critical_lvl">Critical Level:</label>
<div class="col-sm-4">
<input type="number" class="form-control" id="item_critical_lvl" name="item_critical_lvl" autocomplete="off" required> </div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="item_sub_category">Description:</label>
<div class="col-sm-10">
<textarea class="form-control" id="item_description" name="item_description" autocomplete="off" required></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" name="add_item"><span class="glyphicon glyphicon-plus"></span> Add</button>
<button type="button" class="btn btn-warning" data-dismiss="modal"><span class="glyphicon glyphicon-remove-circle"></span> Cancel</button>
</div>
</form>
</div>
</div>
</div>
I want to get the value of a textbox (the value of order_id, to be more specific) from ordermodal.php then pass it to ordermodal2.php. In order to use it in my query.
This is my code for ordermodal.php
include_once 'ordermodal2.php';
/** *ordermodal.php **/
$id = "";
$order_date = "";
$order_time = "";
$order_id = "";
$order_deliverCharge = "";
$order_status = "";
$order_totalAmount= "";
$coordinates = "";
$driver_number = "";
$address = "";
$food_name="";
$special_request="";
$quantity="";
$amount="";
$orders="";
?>
<!-- MODALS --> <!-- DETAILS -->
<div id="myModal" class="modal fade" role="dialog" style="z-index: 1400;">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<form action="" method="post" class="form-horizontal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><center>×</button>
<h4 class="modal-title" id="titleModal">Order Information</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="order_id" class="col-sm-2 control-label">Order ID</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="ORDER_ID" id="ORDER_ID" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="id" class="col-sm-2 control-label">User ID</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="user_id" id="user_id" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_date" class="col-sm-2 control-label">Order Date</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_date" id="order_date" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_time" class="col-sm-2 control-label">Order Time</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_time" id="order_time" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_deliverCharge" class="col-sm-2 control-label">Delivery Charge</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_deliveryCharge" id="order_deliveryCharge" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_totalAmount" class="col-sm-2 control-label">Total Amount</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_totalAmount" id="order_totalAmount" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="address" class="col-sm-2 control-label">Address</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="address" id="address" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="coordinates" class="col-sm-2 control-label">Coordinates</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="coordinates" id="coordinates" placeholder="" value="" required="required" maxlength="11" readonly>
</div>
</div>
<div class="form-group">
<label for="driver_number" class="col-sm-2 control-label">Driver Number</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="driver_number" id="driver_number" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_status" class="col-sm-2 control-label">Order Status</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_status" id="order_status" placeholder="" value="" required="required" readonly>
</div>
</div>
<?php
$order_id = trim(addslashes($_POST['ORDER_ID']));
$sql = "SELECT food_name, special_request, quantity, amount
FROM cart_tbl
WHERE order_id=$order_id";
$result = mysqli_query(connection(), $sql);
?>
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Food</th>
<th>Special Request</th>
<th>Quantity</th>
<th>Amount</th>
</tr>
</thead>
<?php
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["food_name"];?></td>
<td><?php echo $row["special_request"];?></td>
<td><?php echo $row["quantity"];?></td>
<td><?php echo $row["amount"];?></td>
</tr>
<?php
}
}
?>
</table>
<tbody>
</div>
<div class="modal-footer">
<button type="submit" input style="background-color:#4CAF50;color:white" name="submitDelivered" id="submitDelivered" class="btn btn-primary " onclick="if(!confirm('Are you sure you want to deliver order?')){return false;}" > Delivered </button>
<button type="submit" input style="background-color:#0000FF;color:white" name="submitAccept" id="submitAccept" class="btn btn-primary" onclick="if(!confirm('Are you sure you want to accept order?')){return false;}" > Accept </button>
<button type="button" style="background-color:#FFFF00;color:black" class="btn btn-success" data-toggle="modal" data-target="#myDropdown" onclick="send('<?= $_POST['ORDER_ID'] ?>')"> Send </button>
<button type="submit" input style="background-color:#f44336;color:white" name="submitCancel" class="btn btn-danger" onclick="if(!confirm('Are you sure you want to cancel order?')){return false;}">Cancel</button>
<?php
if(isset($_POST['submitDelivered'])){
$ororder_id = trim(addslashes($_POST['ORDER_ID']));
$query = "UPDATE order_tbl SET `order_status`='Delivered' WHERE `order_id` = $order_id";
if (mysqli_query(connection(), $query)) {
mysqli_query(connection(), "COMMIT");
$_SESSION['message'] = "Order Delivered"; }
else {
$_SESSION['message'] = mysqli_error(connection());
mysqli_query(connection(), "ROLLBACK");
}
}
if(isset($_POST['submitAccept'])){
$order_id = trim(addslashes($_POST['ORDER_ID']));
$query = "UPDATE order_tbl SET `order_status`='Accepted' WHERE `order_id` = $order_id";
if (mysqli_query(connection(), $query)) {
mysqli_query(connection(), "COMMIT");
$_SESSION['message'] = "Order Accepted"; }
else {
$_SESSION['message'] = mysqli_error(connection());
mysqli_query(connection(), "ROLLBACK");
}
}
if(isset($_POST['submitCancel'])){
$order_id = trim(addslashes($_POST['ORDER_ID']));
$query = "UPDATE order_tbl SET `order_status`='Cancelled' WHERE `order_id` = $order_id";
if (mysqli_query(connection(), $query)) {
mysqli_query(connection(), "COMMIT");
$_SESSION['message'] = "Order Cancelled"; }
else {
$_SESSION['message'] = mysqli_error(connection());
mysqli_query(connection(), "ROLLBACK");
}
}
?>
</div>
</form>
</div>
</div>
</div>
<script>
function send(order_id) {
document.getElementById("titleModal2").innerHTML = "Choose Driver";
document.getElementsByName("ORDER_ID_MODAL_2")[0].setAttribute("value", order_id);
document.getElementsByName("send")[0].setAttribute("name", "send");
}
</script>
And this is the code for my ordermodal2.php
<!-- Modal -->
<div class="modal fade" id="myDropdown" role="dialog" style="z-index: 1600;">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<form action="" method="post" class="form-horizontal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">× </button>
<h4 class="modal-title" id="titleModal2">Choose Driver</h4>
</div>
<div class="modal-body" >
<div class="form-group">
<label for="order_id" class="col-sm-2 control-label">Order ID</label>
<div class="col-lg-3">
<input type="text" input style="width:450px" class="form-control" name="ORDER_ID_MODAL_2" id="ORDER_ID_MODAL_2" placeholder="" value="" required="required" readonly>
</div>
</div>
<strong> Select Driver : </strong>
<select name="empName">
<option value=""> -----------ALL----------- </option>
<?php
$databaseHost = "localhost";
$databaseUser = "";
$databasePassword = "";
$databaseName = "";
$con=mysql_connect($databaseHost ,$databaseUser ,$databasePassword )or die ('Connection Error');
mysql_select_db("",$con) or die ('Database Error');
$dd_res=mysql_query("SELECT driver_number FROM driver_tbl");
while($r=mysql_fetch_row($dd_res))
{
echo "<option value='$r[0]'> $r[0] </option>";
}
?>
</select>
</div>
<div class="modal-footer">
<button type="submit" input style="background-color:#FFFF00;color:black" name="send" class="btn btn-primary"onclick="if(!confirm('Are you sure you want to send order?')){return false;}" >Confirm!</button>
<?php
if(isset($_POST['send'])){
$order_id = trim(addslashes($_POST['ORDER_ID_MODAL_2']));
$query = "UPDATE order_tbl SET `order_status`='Dispatched' WHERE `order_id` = $order_id";
if (mysqli_query(connection(), $query)) {
mysqli_query(connection(), "COMMIT");
$_SESSION['message'] = "Order Dispatched"; }
else {
$_SESSION['message'] = mysqli_error(connection());
mysqli_query(connection(), "ROLLBACK");
}
}
?>
</div>
</form>
</div>
</div>
</div>
The output will be: when I click the send button in ordermodal then the ordermodal2 will popup obviously,then the Order Id textbox have a value in it already when send button from ordermodal is clicked(the value is same with the ordermodal.php) then when i click the send button in ordermodal2(this is where i need that value) it will change the driver status to dispatched. I hope you can help me with my problem. TIA!
From reading your code, it looks like it should be simple.....
Change
document.getElementsByName("ORDER_ID_MODAL_2")[0].setAttribute("value", order_id);
To
document.getElementsByName("ORDER_ID_MODAL_2")[0].value('<?php echo $order_id?>');
im using bootstrap 3 framework and codeigniter 3, i want to edit a row from table but i want to display row in thier field in modal
Code Html of table
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Nom et prénom</th>
<th>Age</th>
<th>Sexe</th>
<th>Assurance</th>
<th>Téléphone</th>
<th>E-mail</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
foreach ($query->result() as $row)
{
?>
<tr>
<td><?php echo $row->no_dossier_pt; ?></td>
<td><?php echo $row->nom_pt .' '. $row->prenom_pt ?></td>
<?php
$date = new DateTime($row->datenaissance_pt);
$now = new DateTime();
$interval = $now->diff($date);
?>
<td><?php echo $interval->y .' ans'; ?></td>
<td><?php echo $row->sexe_pt; ?></td>
<td><?php echo $row->assurance_pt; ?></td>
<td><?php echo $row->telephone_pt; ?></td>
<td><?php echo $row->email_pt; ?></td>
<td>
<a type="button" href="<?php echo base_url() ?>patient/patient_delete/<?php echo $row->id; ?>" class="btn btn-danger">Supprimer</a>
<a type="button" data-toggle="modal" href="#editpatient" data-id="<?php echo $row->id; ?>" class="btn btn-warning" >Editer</a>
<?php $this->load->view('template/patient_update'); ?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php
$this->load->view('template/footer');
?>
but i can't understand how can i pass 'id' of this row to the controller and return the specific data row from controller to thier field in Modal form,
this is code of button
<a type="button" data-toggle="modal" href="#editpatient" data-id="<?php echo $row->id; ?>" class="btn btn-warning" >Editer</a>
and my Modal form Code
<!-- Modal -->
<div class="modal fade" id="editpatient" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"> Information patient 2</h4>
</div>
<!-- formulaire -->
<?php echo form_open('patient/patient_update'); // action to the controller?>
<div class="modal-body">
<!-- hidden input montinned with class sr-only -->
<label class="sr-only" =""></label>
<input type="text" name="no_dossier_pt" class="sr-only" >
<div class="form-group">
<input type="text" class="form-control" id="nom_pt" name="nom_pt" id="nom_pt" placeholder="Nom ...">
</div>
<div class="form-group">
<input type="text" class="form-control" id="prenom_pt" name="prenom_pt" id="prenom_pt" placeholder="Prénom ....">
</div>
<div class="form-group">
<label for="exampleInputFile">Sexe : </label>
<input type="radio" name="sexe_pt" id="radio-choice-1" value="homme" checked="checked" />
<label for="radio-choice-1"> Homme </label>
<input type="radio" name="sexe_pt" id="radio-choice-2" value="femme" />
<label for="femme"> Femme </label>
<input type="radio" name="sexe_pt" id="radio-choice-3" value="enfant" />
<label for="enfant">Enfant</label>
</div>
<div class="form-group ">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-calendar">
</i>
</div>
<input class="form-control" id="date" name="date" placeholder="Date de naissance" type="text"/>
</div>
</div>
<div class="form-group">
<label for="exampleInputFile">Assurance : </label>
<input type="radio" name="assurance_pt" id="radio-choice-1" value="oui" checked="checked" />
<label for="radio-choice-1"> Oui </label>
<input type="radio" name="assurance_pt" id="radio-choice-2" value="non" />
<label for="femme"> Non </label>
</div>
<div class="form-group">
<input type="text" class="form-control" name ="telephone_pt" placeholder="Téléphone ...">
</div>
<div class="form-group">
<input type="text" class="form-control" name ="email_pt" placeholder="Email ...">
</div>
<div class="form-group">
<textarea class="form-control" cols="40" name="note_pt" rows="3" placeholder="Note sur ce patient ..."></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
<button type="submit" class="btn btn-primary">Enregistrer</button>
</div>
<?php echo form_close(); ?>
</div>
</div>
</div>
<!-- Modal -->
Controller Methode to display
public function patient_selectbyid()
{
$data = array();
$id = $this->input->post('pt_id');
$this->load->model('patient_model');
$data = $this->studentModel->getStudent($id);
echo $data;
}
Code jquery
$(document).ready(function() {
var id_edit = $(this).data('id');
var base_url = <? php echo base_url('patient/patient_selectbyid'); ?> ;
$('.editStudent').click(function() {
$.ajax({
url: base_url,
type: 'POST',
data: {
'pt_id': id_edit
},
dataType: 'JSON';
success: function(result) {
$('.modal-body #nom_pt').val(result[0].nom_pt);
$('.modal-body #prenom_pt').val(result[0].prenom_pt);
}
});
});
});
I hope someone can help me coding this, thanks you
thanks brother for your recommandations , i had resolve the problem by using event listner as you say, i just sent data DB using data attribute in the button like this:
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#editPatient" data-id="<?php echo $row->id ?>" data-nom="<?php echo $row->nom_pt ?>" data-prenom="<?php echo $row->prenom_pt ?>" data-nod="<?php echo $row->no_dossier_pt ?>" data-sexe="<?php echo $row->sexe_pt; ?>" data-dn="<?php echo $row->datenaissance_pt; ?>" data-assur="<?php echo $row->assurance_pt; ?>" data-tele="<?php echo $row->telephone_pt; ?>" data-email="<?php echo $row->email_pt; ?>" data-note="<?php echo $row->note_pt; ?>" >
Modifier
the modal like this
<!-- Modal -->
<div class="modal fade" id="editPatient" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"> Information patient </h4>
</div>
<div class="modal-body">
<!-- formulaire -->
<?php echo form_open('patient/patient_update'); ?>
<label class="sr-only" =""></label>
<input type="text" name="id" class="sr-only" id="id_hidd" >
<div class="form-group">
<input type="text" class="form-control" id="nom_pt" name="nom_pt" placeholder="Nom ...">
</div>
<div class="form-group">
<input type="text" class="form-control" id="prenom_pt" name="prenom_pt" placeholder="Prénom ....">
</div>
<div class="form-group">
<label for="exampleInputFile">Sexe : </label>
<input type="radio" name="sexe" id="homme" value="homme" checked="checked" />
<label for="homme"> Homme </label>
<input type="radio" name="sexe" id="femme" value="femme" />
<label for="femme"> Femme </label>
<input type="radio" name="sexe" id="enfant" value="enfant" />
<label for="enfant">Enfant</label>
</div>
<div class="form-group ">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-calendar">
</i>
</div>
<input class="form-control" id="date" name="date" placeholder="Date de naissance" type="text"/>
</div>
</div>
<div class="form-group">
<label for="exampleInputFile">Assurance : </label>
<input type="radio" name="assurance" id="assur" value="oui" checked="checked" />
<label for="radio-choice-1"> Oui </label>
<input type="radio" name="assurance" id="nonassur" value="non" />
<label for="femme"> Non </label>
</div>
<div class="form-group">
<input type="text" class="form-control" id="telephone_pt" name ="telephone_pt" placeholder="Téléphone ...">
</div>
<div class="form-group">
<input type="text" class="form-control" id ="email_pt" name ="email_pt" placeholder="Email ...">
</div>
<div class="form-group">
<textarea class="form-control" cols="40" id="note_pt" name="note_pt" rows="3" placeholder="Note sur ce patient ..."></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
<button type="submit" class="btn btn-primary">Enregistrer</button>
</div>
<?php echo form_close(); ?>
</div>
</div>
</div>
script that recive data and displayed on Modal form like this:
<script type="text/javascript">
$('#editPatient').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var id = button.data('id')
var prenom = button.data('prenom')
var nom = button.data('nom')
var nod = button.data('nod')
var sexe = button.data('sexe')
var dn = button.data('dn')
var tele = button.data('tele')
var email = button.data('email')
var note = button.data('note')
if (sexe == 'femme'){
var id_sexe = "femme"
document.getElementById(id_sexe).setAttribute("checked", "checked")
}
if (sexe == 'homme'){
var id_sexe = "homme"
document.getElementById(id_sexe).checked = true
}
if (sexe == 'enfant'){
var id_sexe = "enfant"
document.getElementById(id_sexe).checked = true
}
if (assur == 'oui'){
var id_assur = "assur"
document.getElementById(id_assur).checked = true
}
if (assur == 'non'){
var id_assur = "nonassur"
document.getElementById(id_assur).checked = true
}
var modal = $(this)
modal.find('.modal-title').text('Modifier patient ('+nod+')')
modal.find('.modal-body #id_hidd').val(id)
modal.find('.modal-body #nom_pt').val(nom)
modal.find('.modal-body #prenom_pt').val(prenom)
modal.find('.modal-body #date').val(dn)
modal.find('.modal-body #telephone_pt').val(tele)
modal.find('.modal-body #email_pt').val(email)
modal.find('.modal-body #note_pt').val(note)
})
</script>
thanks for your help if you have any other suggestion or question i'll be gratfull
I have written a javascript click function to a class to display a popup when the relevant class be clicked. When i just put an alert it gives me the correct output. but the popup modal is doesn't show up
Model
I am using following model function
function get_reservation($type, $title, $date_cal)
{
$this->db->select('reservations.*');
$this->db->from('reservations');
$this->db->where('(reservations.type like "' . $type . '%" and reservations.title like "' . $title . '%" and reservations.date_cal like "' . $date_cal . '%" )');
$this->db->where('is_deleted', '0');
$query = $this->db->get();
return $query->result();
}
And i am calling that method in the following controller funtion
Controller
function get_reservations_records()
{
$this->load->model('mycal_model');
$type = $this->input->post('type', TRUE);
$title = $this->input->post('title', TRUE);
$date_cal = $this->input->post('date_cal', TRUE);
$data['reservation_records'] = $this->mycal_model->get_reservation($type,$title,$date_cal);
echo $this->load->view('reservation_list_view', $data);
}
Here i am passing data to another view. and i am calling that method in the javascript.
View
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to CodeIgniter</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<style type="text/css">
#body{
margin: 0 15px 0 15px;
}
#container{
margin: 10px;
border: 1px solid #D0D0D0;
-webkit-box-shadow: 0 0 8px #D0D0D0;
}
.calendar{
/* background-color: yellow;*/
}
table.calendar{
margin: auto;
border-collapse: collapse;
}
.calendar .days td {
width:90px;
height: 100px;
padding: 4px;
border: 1px solid #999;
vertical-align: top;
background-color: #DEF;
}
.calendar .days td:hover{
background-color: #fff;
}
.calendar .highlight {
font-weight: bold;
color: #EF1BAC;
}
.calendar .content .rp_am_no{
float: left;
display: inline-block;
width: 40px;
background-color: #E13300;
}
</style>
</head>
<body>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".calendar .content .rp_am_no").click(function() {
var title = "RP";
var type = "AM";
var date_cal = $(this).attr("id");
$.ajax({
type: 'POST',
url: '<?php echo site_url(); ?>/my_calendar/get_reservations_records',
data: "type=" + type + "&title=" + title + "&date_cal=" + date_cal,
success: function(msg) {
//alert(msg);
$('#reservation_detail_model_body').html(msg);
$('#reservation_detail_model').modal('show');
},
error: function(msg) {
alert("Error Occured!");
}
});
});
});
</script>
<div id="container">
<div id="body">
<?php echo $calendar; ?>
</div>
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="reservation_detail_model" class="modal fade" style="display: none;">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button aria-hidden="true" data-dismiss="modal" class="close" type="button">x</button>
<h4 class="modal-title">Reservation Details</h4>
</div>
<div class="modal-body" id="reservation_detail_model_body">
<!--reservation_list_view goes here-->
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-info" type="button">Close</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
My popup doesn't show up. But when i put an alert and check it gives me the correct output. I can't figure out what is wrong with this. If anyone has an idea it would be a help.
You are including jQuery more than once, you have actually included jQuery in your head section, remove those two before your custom javascript, that's why you are getting $(...).modal is not a function error:
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
Remove style="display: none;" from your <div> tag
Try
$('#reservation_detail_model_body').html(msg);
$('#reservation_detail_model').css('display','block');
<?php
class ajax extends CI_Controller
{
public function get_sms_provider($id)
{
$edit_profile=$this->db->get_where("tbl_sms_provider",array("sms_provider_id"=>$id));
if(isset($edit_profile))
{
foreach($edit_profile->result() as $row)
{
?>
<form role="form" method="post" action="<?php echo base_url(); ?>admin/manage_sms_provider/edit/do_update/<?php echo $row->sms_provider_id ;?>" enctype="multipart/form-data">
<div class="form-group">
<label>SMS Provider Name</label>
<input class="form-control" id="txt_sms_provider_name" name="txt_sms_provider_name" value="<?php echo $row->sms_provider_name ;?>">
</div>
<div class="form-group">
<label>SMS Provider Url</label>
<input class="form-control" id="txt_sms_provider_url" name="txt_sms_provider_url" value="<?php echo $row->sms_provider_url ;?>">
</div>
<div class="form-group">
<label>User Name</label>
<input class="form-control" id="txt_sms_provider_user" name="txt_sms_provider_user" value="<?php echo $row->sms_provider_user ;?>">
</div>
<div class="form-group">
<label>Password</label>
<input class="form-control" id="txt_sms_provider_password" name="txt_sms_provider_password" value="<?php echo $row->sms_provider_password ;?>">
</div>
<div class="form-group">
<label>Status</label>
<?php
$radio_array=array("Active","In-Active");
for($i=0;$i<count($radio_array);$i++)
{
if($radio_array[$i]==$row->sms_provider_status)
{
?>
<input type="radio" checked id="rdo_sms_provider_status" name="rdo_sms_provider_status" value="<?php echo $radio_array[$i]; ?>"><?php echo $radio_array[$i]; ?>
<?php
}
else
{
?>
<input type="radio" id="rdo_sms_provider_status" name="rdo_sms_provider_status" value="<?php echo $radio_array[$i]; ?>"><?php echo $radio_array[$i]; ?>
<?php
}
?>
<?php
}
?>
</div>
<button type="submit" class="btn btn-success">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</form>
<?php
}
}
}
public function get_settings()
{
$edit_profile=$this->db->get_where("tbl_settings");
if(isset($edit_profile))
{
foreach($edit_profile->result() as $row)
{
?>
<form role="form" method="post" action="<?php echo base_url(); ?>admin/manage_settings/edit/do_update" enctype="multipart/form-data">
<div class="control-group success">
<div class="col-lg-6">
<div class="form-group">
<label>Website Title </label>
<input type="text" id="txt_title" name="txt_title" class="form-control" value="<?php echo $row->settings_website_title; ?>" >
</div>
<div class="form-group">
<label>Meta Keywords </label>
<textarea id="txt_keyword" name="txt_keyword" class="form-control" ><?php echo $row->settings_meta_keywords; ?></textarea>
</div>
<div class="form-group">
<label>Meta Description </label>
<textarea id="txt_desc" name="txt_desc" class="form-control" ><?php echo $row->settings_meta_keywords; ?></textarea>
</div>
<div class="form-group">
<label>Website Name </label>
<input type="text" id="txt_name" name="txt_name" class="form-control" value="<?php echo $row->settings_website_title; ?>" >
</div>
<div class="form-group">
<label>Currency Code </label>
<input type="text" id="txt_code" name="txt_code" class="form-control" value="<?php echo $row->settings_currency_code; ?>" >
</div>
<div class="form-group">
<label >Currency Symbol </label>
<input type="text" id="txt_symbol" name="txt_symbol" class="form-control" value="<?php echo $row->settings_currency_symbol; ?>" >
</div>
<div class="form-group">
<label class="control-label" for="typeahead">Address </label>
<textarea id="txt_addr" name="txt_addr" class="form-control" ><?php echo $row->settings_address; ?></textarea>
</div>
<div class="form-group">
<label >Phone </label>
<input type="text" id="txt_phone" name="txt_phone" class="form-control" value="<?php echo $row->settings_phone; ?>" >
</div>
<div class="form-group">
<label >Fax </label>
<input type="text" id="txt_fax" name="txt_fax" class="form-control" value="<?php echo $row->settings_fax; ?>" >
</div>
<div class="form-group">
<label >Contact Email </label>
<input type="text" id="txt_email" name="txt_email" class="form-control" value="<?php echo $row->settings_contact_email; ?>" >
</div>
<div class="form-group">
<label >Map Address </label>
<input type="text" id="txt_map_addr" name="txt_map_addr" class="form-control" value="<?php echo $row->settings_map_address; ?>" >
</div>
<div class="form-group">
<label >Toll Free Number </label>
<input type="text" id="txt_toll_free" name="txt_toll_free" class="form-control" value="<?php echo $row->settings_toll_free; ?>" >
</div>
<div class="form-group">
<label >Minimum Single Piece Qty</label>
<input class="form-control" id="txt_single_min_qty" name="txt_single_min_qty" type="text" value="<?php echo $row->settings_single_min_qty; ?>">
</div>
<div class="form-group">
<label >Minimum Total Piece Qty</label>
<input class="form-control" id="txt_total_min_qty" name="txt_total_min_qty" type="text" value="<?php echo $row->settings_total_min_qty; ?>">
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label >Logo </label>
<br>
<img height='100px' src="<?php echo base_url().'files/admin/logo/'.$row->settings_logo; ?>" >
<input type="file" id="img_logo" name="img_logo" >
</div>
<div class="form-group">
<label>Small Logo </label>
<br>
<img height='100px' src="<?php echo base_url().'files/admin/logo/'.$row->settings_small_logo; ?>" >
<input type="file" id="img_logo_small" name="img_logo_small" >
</div>
<div class="form-group">
<label>Footer Logo </label>
<br>
<img height='100px' src="<?php echo base_url().'files/admin/logo/'.$row->settings_footer_logo; ?>" >
<input type="file" id="img_logo_footer" name="img_logo_footer" >
</div>
<div class="form-group">
<label >Favicon</label>
<br>
<img height='100px' src="<?php echo base_url().'files/admin/logo/'.$row->settings_favicon; ?>" >
<input type="file" id="img_favicon" name="img_favicon" class="span6 typeahead" >
</div>
<div class="form-group">
<label >Facebook Url </label>
<input type="text" id="txt_fb_url" name="txt_fb_url" class="form-control" value="<?php echo $row->facebook_url; ?>" >
</div>
<div class="form-group">
<label >Google+ Url</label>
<input type="text" id="txt_google_url" name="txt_google_url" class="form-control" value="<?php echo $row->google_plus_url; ?>" >
</div>
<div class="form-group">
<label >Twitter Url</label>
<input type="text" id="txt_twitter_url" name="txt_twitter_url" class="form-control" value="<?php echo $row->twitter_url; ?>" >
</div>
<div class="form-group">
<label >Pinterest Url</label>
<input type="text" id="txt_linkedin_url" name="txt_linkedin_url" class="form-control" value="<?php echo $row->pinterest_url; ?>" >
</div>
<div class="form-group">
<label >Instagram Url</label>
<input type="text" id="txt_instagram_url" name="txt_instagram_url" class="form-control" value="<?php echo $row->instagram_url; ?>" >
</div>
<div class="form-group">
<label >Show Badges</label>
<input id="inlineCheckbox1" id="chk_show_badges" name="chk_show_badges" type="checkbox" <?php if(trim($row->settings_show_badges)=="1"){echo " checked='checked'";} ?> value="1">
</div>
</div>
<div class="col-lg-12">
<button type="submit" class="btn btn-success">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</div>
</form>
<?php
}
}
}
public function get_cms()
{
$edit_profile=$this->db->get("tbl_cms");
if(isset($edit_profile))
{
foreach($edit_profile->result() as $row)
{
?>
<form role="form" method="post" action="<?php echo base_url(); ?>admin/manage_cms/edit/do_update" enctype="multipart/form-data">
<div class="col-lg-6">
<div class="form-group">
<label>About Us</label>
<textarea class="form-control" id="txt_about_us" name="txt_about_us" rows="3"><?php echo $row->cms_about_us ;?></textarea>
</div>
<div class="form-group">
<label>Privacy Policy</label>
<textarea class="form-control" id="txt_privacy_policy" name="txt_privacy_policy" rows="3"><?php echo $row->cms_privacy_policy ;?></textarea>
</div>
<div class="form-group">
<label>Copy Right</label>
<textarea class="form-control" id="txt_copy_right" name="txt_copy_right" rows="3"><?php echo $row->cms_copy_right ;?></textarea>
</div>
<div class="form-group">
<label>Trade Mark</label>
<textarea class="form-control" id="txt_trademark" name="txt_trademark" rows="3"><?php echo $row->cms_trademark ;?></textarea>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label>Terms & Conditions</label>
<textarea class="form-control" id="txt_terms_conditions" name="txt_terms_conditions" rows="3"><?php echo $row->cms_terms_conditions ;?></textarea>
</div>
<div class="form-group">
<label>Contact Us</label>
<textarea class="form-control" id="txt_contact_us" name="txt_contact_us" rows="3"><?php echo $row->cms_contact_us ;?></textarea>
</div>
<div class="form-group">
<label>Bank Details</label>
<textarea class="form-control" id="txt_bank_details" name="txt_bank_details" rows="3"><?php echo $row->cms_bank_details ;?></textarea>
</div>
</div>
<div class="col-lg-12">
<button type="submit" class="btn btn-success">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</div>
</form>
<?php
}
}
}
public function get_slider($id)
{
$edit_profile=$this->db->get_where("tbl_slider",array("slider_id"=>$id));
if(isset($edit_profile))
{
foreach($edit_profile->result() as $row)
{
?>
<form role="form" method="post" action="<?php echo base_url(); ?>admin/manage_slider/edit/do_update/<?php echo $row->slider_id ;?>" enctype="multipart/form-data">
<div class="form-group">
<label>Title</label>
<input class="form-control" id="txt_slider_title" name="txt_slider_title" value="<?php echo $row->slider_title ;?>">
</div>
<div class="form-group">
<label>Slider Image</label><br><img src="<?php echo base_url(); ?>files/user/slider/<?php echo $row->slider_image; ?>" width="200px"><input type="file" id="img_slider" name="img_slider">
</div>
<div class="form-group">
<label>Href</label>
<input class="form-control" id="txt_slider_href" name="txt_slider_href" value="<?php echo $row->slider_href ;?>">
</div>
<div class="form-group">
<label>Order Number</label>
<input class="form-control" id="txt_slider_order" name="txt_slider_order" value="<?php echo $row->slider_order ;?>">
</div>
<div class="form-group">
<label>Content</label>
<input class="form-control" id="txt_slider_content" name="txt_slider_content" value="<?php echo $row->slider_content ;?>">
</div>
<div class="form-group">
<label>Position</label>
<input class="form-control" id="txt_slider_position" name="txt_slider_position" value="<?php echo $row->slider_content_position ;?>">
</div>
<div class="form-group">
<label>Status</label>
<?php
$radio_array=array("Active","In-Active");
for($i=0;$i<count($radio_array);$i++)
{
if($radio_array[$i]==$row->slider_status)
{
?>
<input type="radio" checked id="rdo_status" name="rdo_status" value="<?php echo $radio_array[$i]; ?>"><?php echo $radio_array[$i]; ?>
<?php
}
else
{
?>
<input type="radio" id="rdo_status" name="rdo_status" value="<?php echo $radio_array[$i]; ?>"><?php echo $radio_array[$i]; ?>
<?php
}
?>
<?php
}
?>
</div>
<button type="submit" class="btn btn-success">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</form>
<?php
}
}
}
public function manage_slider($order_id,$order_status)
{
$data['order_status']=$order_status;
$this->db->where('order_id',$order_id);
$this->db->update('tbl_order',$data);
echo '<div class="alert alert-success">
×
<strong>Order Status Changed Successfully to : '.$order_status.'</strong>
</div>';
}
}
?>