Get the value of textbox then pass to another modal - javascript

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?>');

Related

How to insert value in table by ID?

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 have to give some dependent fields in html,php,javascript

I need to give some dependency in the fields. Ex:
first i have two option that is Branch/Staff so, if i am selecting branch it should display the branches to select if he is selecting staff then i should be able to select the employee id and if am selecting employee id employee name should display and more over all these things user needs to feed the data. That is main category branch/staff should be standard but there after branches,employee number and name al these things user needs to feed
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function updatePrice() {
// Get the ex-GST price from its form element
var exPrice = document.getElementById("product_price").value;
var gstPrice = document.getElementById("cgst").value;
// Get the GST price
gstPrice = exPrice * 0.09;
var TPrice = parseInt(gstPrice) + parseInt(exPrice) + parseInt(gstPrice);
// Set the GST price in its form element
document.getElementById("cgst").value = gstPrice;
document.getElementById("igst").value = gstPrice;
document.getElementById("sgst").value = 0;
document.getElementById("total").value = TPrice;
}
</script>
</head>
<body>
<?php
public function addProduct($pro_name,$price,$stock,$date,$loc,$in_no,$gst_no,$cgst,$sgst,$igst,$total,$depre,$pur_from){
$pre_stmt = $this->con->prepare("INSERT INTO `products`( `product_name`, `product_price`, `product_stock`, `added_date`, `p_status`, `loc`, `in_no`, `gst_no`, `cgst`, `sgst`, `igst`, `total`, `depre`, `pur_from`)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$status = 1;
$pre_stmt->bind_param("sdisisiiddddis",$cid,$bid,$pro_name,$price,$stock,$date,$status,$loc,$in_no,$gst_no,$cgst,$sgst,$igst,$total,$depre,$pur_from);
$result = $pre_stmt->execute() or die($this->con->error);
if ($result) {
return "NEW_PRODUCT_ADDED";
}else{
return 0;
}
}
if (isset($_POST["added_date"]) AND isset($_POST["product_name"]) ) {
$obj = new DBOperation();
$result = $obj->addProduct($_POST["select_cat"],
$_POST["select_brand"],
$_POST["product_name"],
$_POST["product_price"],
$_POST["product_qty"],
$_POST["added_date"],
$_POST["loc"],
$_POST["in_no"],
$_POST["gst_no"],
$_POST["cgst"],
$_POST["sgst"],
$_POST["igst"],
$_POST["total"],
$_POST["depre"],
$_POST["pur_from"]);
echo $result;
exit();
}
?>
<div class="modal fade" id="form_products" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add new products</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="product_form" onsubmit="return false">
<div class="form-group">
<label>Category</label>
<select class="form-control" id="select_cat" name="select_cat" required/>
</select>
</div>
<div class="form-group">
<label>Brand</label>
<select class="form-control" id="select_brand" name="select_brand" required/>
</select>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>RHFL ID</label>
<input type="text" class="form-control" name="product_name" id="product_name" placeholder="Enter RHFL ID" required>
</div>
<div class="form-group col-md-6">
<label>Invoice No</label>
<input type="text" class="form-control" name="in_no" id="in_no" placeholder="Enter Invoice No" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Location</label>
<input type="text" class="form-control" id="loc" name="loc" placeholder="Enter Location" required/>
</div>
<div class="form-group col-md-6">
<label>Purchase Date</label>
<input type="text" class="form-control" id="added_date" name="added_date" value="<?php echo date("Y-m-d"); ?>" readonly/>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Product Price</label>
<input type="text" class="form-control" id="product_price" name="product_price" onChange="updatePrice()" />
</div>
<div class="form-group col-md-6">
<label>GST No</label>
<input type="text" class="form-control" id="gst_no" name="gst_no" placeholder="Enter GST No" required/>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Purchased From</label>
<input type="text" class="form-control" id="pur_from" name="pur_from" placeholder="Enter From Where you purchased" required/>
</div>
<div class="form-group col-md-6">
<label>IGST</label>
<input type="text" class="form-control" id="igst" name="igst" onChange="updatePrice()" />
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="cgst">CGST</label>
<input type="text" class="form-control" id="cgst" name="cgst" readonly name="cgst" onChange="updatePrice()" />
</div>
<div class="form-group col-md-6">
<label>SGST</label>
<input type="text" class="form-control" id="sgst" name="sgst" onChange="updatePrice()" />
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Quantity</label>
<input type="text" class="form-control" id="product_qty" name="product_qty" placeholder="Enter Quantity" required/>
</div>
<div class="form-group col-md-6">
<label>Depreciation</label>
<input type="text" class="form-control" id="depre" name="depre" placeholder="Enter Price of SGST" required/>
</div>
</div>
<div class="form-group">
<label>Total</label>
<input type="text" class="form-control" id="total" name="total" onChange="updatePrice(this.form)" />
</div>
<button type="submit" class="btn btn-success">Add Product</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
//add product
$("#product_form").on("submit",function(){
$.ajax({
url : DOMAIN+"/includes/process.php",
method : "POST",
data : $("#product_form").serialize(),
success : function(data){
if (data == "NEW_PRODUCT_ADDED") {
alert("New Product Added Successfully..!");
$("#product_name").val("");
$("#select_cat").val("");
$("#select_brand").val("");
$("#product_price").val("");
$("#product_qty").val("");
calculate();
}else{
console.log(data);
alert(data);
}
}
})
})

populate field with data from DB in Modal Bootstrap 3 using Codeigniter and jquery

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

editing multiple users using modal form (javascript, html)

Hi guys the issue I have is within my users admin page, I have displayed all the admin users within a table each assigned a delete and edit button.
When I click on edit the given users details appear in a modal form. Within the edit details there is a password and confirm password box, when I click on the edit details for the first user, the validation for confirm password appears as "passwords don't match" however when I click on the second user the confirm password does not validate.
Below is the source code I am having issues with any help will be much appreciated:
<a rel="tooltip" title="Edit" id="e<?php echo $id; ?>" href="#edit<?php echo $id; ?>" data-toggle="modal" class="btn btn-success"></i>Edit</a>
<div id="edit<?php echo $id;?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-body">
<div class="alert alert-info"><strong>Edit User</strong></div>
<form class="form-horizontal" method="post">
<div class="control-group">
<label class="control-label" for="inputEmail">Firstname</label>
<div class="controls">
<input type="text" id="inputEmail" name="firstname" value="<?php echo $row['firstname']; ?>" required>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Lastname</label>
<div class="controls">
<input type="text" id="inputEmail" name="lastname" value="<?php echo $row['lastname']; ?>" required>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Mobile Number</label>
<div class="controls">
<input type="text" id="inputEmail" name="mobilenumber" value="<?php echo $row['mobilenumber']; ?>" required>
</div>
</div>
<input type="hidden" id="inputEmail" name="id" value="<?php echo $row['admin_id']; ?>" required>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="text" name="password" id="password" required>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Confirm Password</label>
<div class="controls">
<input type="text" name="confirmpassword" id="confirmpassword" required>
</div>
</div>
<div class="control-group">
<div class="controls">
<button name="edit" type="submit" class="btn btn-success"> Update</button>
</div>
</div>
<script type="text/javascript">
window.onload = function () {
document.getElementById("password").onchange = validatePassword;
document.getElementById("confirmpassword").onchange = validatePassword;
}
function validatePassword(){
var confirmpassword=document.getElementById("confirmpassword").value;
var password=document.getElementById("password").value;
if(password!=confirmpassword)
document.getElementById("confirmpassword").setCustomValidity("Passwords Don't Match");
else
document.getElementById("confirmpassword").setCustomValidity('');
//empty string means no validation error
}
</script>
</form>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"> Close</button>
</div>
</div>
<?php
if (isset($_POST['edit'])){
$admin_id=$_POST['id'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$mobilenumber=$_POST['mobilenumber'];
$password= sha1 ($_POST['password']);
mysql_query("update admin set firstname = '$firstname', lastname = '$lastname', mobilenumber = '$mobilenumber', password = '$password' where admin_id='$admin_id'")or die(mysql_error()); ?>
<script>
window.location="adminusers.php";
</script>
<?php
}
}
?>
Validation issue
Validation issue 2

how to populate the fields in my bootstrap modal from clicking a row in the view table in codeigniter

I have this bootstrap3 modal that is called when I click a certain row in a table and shows the details of a student supposedly ready for editing. But the problem is the details doesn't appear in the fields where I put the value via ajax. By the way I am using Codeigniter as my php framework.
I am looking for solutions for days now but still can't find the right answer for my problem...
This is my Controller
public function getStudent(){
$data = array();
$id = $this->input->post('stud_id');
$this->load->model('studentModel');
$data = $this->studentModel->getStudent($id);
echo $data;
}
Model
public function getStudent($id){
$query = array();
$this->db->select('*');
$this->db->from('stud_bio');
$this->db->where('stud_id', $id);
$query = $this->db->get();
return $query->result();
}
View
<div class="container">
<div class="row">
<div class="table table-responsive">
<table class="table table-hover table-striped table-condensed table-bordered">
<thead class="header">
<tr>
<th>Name</th>
<th>Gender</th>
<th>Marital Status</th>
<th>Name of Spouse</th>
<th>Number of Children</th>
<th>Date of Birth</th>
<th>Contact Number</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<?php foreach($data as $row){ ?>
<tr data-toggle="modal" href="#editStudent" data-id="<?php echo $row->stud_id?>" class="editStudent">
<td><?php echo $row->name?></td>
<td><?php if($row->gender == 1){echo "Male";}else{echo "Female";} ?></td>
<td><?php if($row->marital_status == 1){echo "Single";}else{echo "Married";}?></td>
<td><?php echo $row->spouse_name ?></td>
<td><?php echo $row->no_of_children ?></td>
<td><?php echo $row->DOB ?></td>
<td><?php echo $row->contactNo ?></td>
<td><?php echo $row->email ?></td>
<?php }?>
</tbody>
</table>
</div>
</div>
Modal
<div class="container">
<div class="row">
<div class="modal fade" id="editStudent" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<?=form_open(base_url('admin/studentController/editStudent'))?>
<div class="form-horizontal">
<div class="modal-header"><!--HEADER-->
<button class="btn btn-primary close" data-dismiss="modal" aria-hidden="true">×</button>
<h4>Edit Student</h4>
</div><!--end of HEADER-->
<div class="modal-body"><!--BODY-->
<!--Name-------------------------------------------->
<div class="form-group">
<label for="edit_fullname" class="col-sm-2 control-label">Fullname</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="edit_fullname" name="edit_fullname" placeholder="Name">
</div>
<label class="radio-inline has-error">
<?php echo form_error('edit_fullname','*<span3 class="help-inline">','</span3>'); ?>
</label>
</div><!--end of NAME -->
<!--Gender------------------------------------------>
<div class="form-group">
<label class="col-sm-2 control-label">Gender</label>
<div class="col-sm-4">
<label for="edit_male" class="radio-inline">
<input type="radio" name="edit_genderRadio" value="1" id="edit_male"/>Male
</label>
<label for="edit_female" class="radio-inline">
<input type="radio" name="edit_genderRadio" value="2" id="edit_female"/>Female
</label>
</div>
<label class="radio-inline has-error">
<?php echo form_error('edit_genderRadio','*<span3 class="help-inline">','</span3>'); ?>
</label>
</div>
<!--Civil Status----------------------------------->
<div class="form-group">
<label class="col-sm-2 control-label">Civil Status</label>
<div class="col-sm-4">
<label for="edit_S" class="radio-inline">
<input type="radio" name="edit_civilRadio" value="1"<?=set_radio('civilRadio', '1')?> id="edit_S"/>Single
</label>
<label for="edit_M" class="radio-inline">
<input type="radio" name="edit_civilRadio" value="2"<?=set_radio('civilRadio', '2')?> id="edit_M"/>Married
</label>
</div>
<label class="radio-inline has-error">
<?php echo form_error('edit_civilRadio','*<span3 class="help-inline">','</span3>'); ?>
</label>
</div>
<!--If Married Spouse name--------------------------------->
<div class="form-group">
<label for="edit_spouseName" class="col-sm-2 control-label">Spouse Name</label>
<div class="col-sm-4">
<input type="text" name="edit_spouseName" id="edit_spouseName" class="form-control" placeholder="Spouse name"/>
</div>
<label class="radio-inline has-error">
<?php echo form_error('edit_spouseName','*<span3 class="help-inline">','</span3>'); ?>
</label>
</div>
<!--Children #------------------------------------------------->
<div class="form-group">
<label for="edit_numChildren" class="col-sm-2 control-label">Number of Children</label>
<div class="col-md-2">
<input type="text" class="form-control" name="edit_numChildren" id="edit_numChildren" placeholder="- - -"/>
</div>
<label class="radio-inline has-error">
<?php echo form_error('edit_numChildren','*<span3 class="help-inline">','</span3>'); ?>
</label>
</div>
<!--Date of birth--------------------------------------------------->
<div class="form-group">
<label for="edit_DOB" class="col-sm-2 control-label">Date of Birth</label>
<div class="col-sm-4">
<div class='input-group date' data-date-format="yyyy/mm/dd">
<input type='text' class="form-control" readonly="" name="edit_DOB" id="edit_DOB" />
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
</div>
</div>
<label class="radio-inline has-error">
<?php echo form_error('edit_DOB','*<span3 class="help-inline">','</span3>');?>
</label>
</div>
<!--Email----------------------------------------------------------->
<div class="form-group">
<label for="edit_email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-4">
<input type="email" id="edit_email" name="edit_email" class="form-control" placeholder="Enter email.."/>
</div>
<label class="radio-inline has-error">
<?php echo form_error('edit_email','*<span3 class="help-inline">','</span3>');?>
</label>
</div>
<!--Contact Number--------------------------------------------------------->
<div class="form-group">
<label for="edit_contactNo" class="col-sm-2 control-label">Contact No.</label>
<div class="col-sm-4">
<input type="text" id="edit_contactNo" name="edit_contactNo" class="form-control" placeholder="Contact No." />
</div>
<label class="radio-inline has-error">
<?php echo form_error('edit_contactNo','*<span3 class="help-inline">','</span3>');?>
</label>
</div>
</div> <!--end of BODY-->
<div class="modal-footer"><!--FOOTER-->
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Save</button>
</div><!--end of FOOTER-->
</div><!--end of form-horizontal -->
<?=form_close()?>
</div>
</div>
</div>
</div>
Script
<script type="text/javascript">
$(document).ready(function(){
var id_edit = $(this).data('id');
var base_url = <?php echo base_url('admin/studentController/getStudent');?>;
$('.editStudent').click(function (){
$.ajax({
url: base_url,
type: 'POST',
data: { 'stud_id': id_edit},
dataType: 'JSON';
success: function(result){
$('.modal-body #edit_fullname').val(result[0].name);
$('.modal-body .edit_genderRadio').val(result[0].gender);
$('.modal-body .edit_civilStatus').val(result[0].marital_status);
$('.modal-body #edit_spouseName').val(result[0].spouse_name);
$('.modal-body #edit_numChildren').val(result[0].no_of_children);
$('.modal-body .edit_DOB').val(result[0].DOB);
$('.modal-body #edit_email').val(result[0].email);
$('.modal-body #edit_contactNo').val(result[0].contactNo);
}
});
});
});
</script>

Categories

Resources