<?php
foreach ($employee as $data) {
?>
<tr>
<td>
<form action="<?php echo base_url();?>controller_admin/updateEmployee/<?php echo $data->id_employee;?>" method="post">
<select style="width: 100px; height: 33px;" name="directorate" id="directorate">
<option selected value="<?php echo $data->id_directorate ?>"><?php echo $data->directorate ?></option>
<?php
foreach ($directorate as $key) {
if ($data->directorate != $key->directorate) {?>
<option value="<?php echo $key->id_directorate ?>">
<?php echo $key->directorate; ?>
</option>
<?php
}
}
?>
</select>
</td>
<td>
<select style="width: 100px; height: 33px;" name="department" id="department">
<?php if ($data->id_department!=null) {?>
<option value="0"></option>
<?php
} ?>
<option selected value="<?php echo $data->id_department ?>"><?php echo $data->department; ?></option>
<?php
$value = 1;
foreach ($department as $key) {
if ($data->department != $key->department) {?>
<option
class="<?php echo $key->id_directorate ?>"
value="<?php echo $value ?>">
<?php echo $key->department; ?>
</option>
<?php
$value++;
}
}
?>
</select>
</td>
<td>
<select style="width: 100px; height: 33px;" name="section" id="section">
<?php if ($data->id_section!=null): ?>
<option value="0"></option>
<?php endif ?>
<option selected value="<?php echo $data->id_section ?>"><?php echo $data->section; ?></option>
<?php
$value = 1;
foreach ($section as $key) {
if ($data->section != $key->section) {?>
<option
class="<?php echo $key->id_department ?>"
value="<?php echo $value ?>">
<?php echo $key->section; ?>
</option>
<?php
$value++;
}
}
?>
</select>
</td>
<td>
<button type="submit" class="btn btn-warning"><i class="fa fa-edit"></i></button>
<button type="button" class="btn btn-danger"><i class="fa fa-trash-o"></i></button>
</form>
</td>
<?php
}
?>
<script src="<?php echo base_url();?>assets/js/jquery.chained.min.js"></script>
<script>
$("#department").chained("#directorate");
$("#section").chained("#department");
</script>
I want to make a list of table to display chained dropdown to display like this:
and chained dropdown work like this:
but, it will display in first row only, at another row, it does not work.
You can look like this:
I hope I can chained dropdown for all rows. Anyone find the solution?
you could try to put your js code inside the ready function - its possible that the elements are not even rendered when you try to select them.
<script>
$( document ).ready(function() {
$("#department").chained("#directorate");
$("#section").chained("#department");
});
</script>
reference: http://learn.jquery.com/using-jquery-core/document-ready/
Related
I am Calling this File using Ajax But this file is displaying but without selectpicker, I don't see any error if anyone can help me?
Bootstrap Selectpicker Will Show Timing From Monday to Sunday
IF condition is used to check whether this time is present in the database or not if present check the checkbox and show the time in bootstrap Selectpciker
All the condition displaying in this file is important I cant remove them
<?php
error_reporting(E_ALL);
ini_set("display_errors",1);
require_once'configuration/config.php';
date_default_timezone_set("Asia/Kolkata");
$startTime = strtotime(date("H:i:s",strtotime('00:00:00')));
$endTime = strtotime(date('H:i:s',strtotime('23:59:00')));
if(isset($_POST['doc_id'])){
$days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
$doc_id ='921007GAURAV984934';
$hp_id = 'INRJAPPO2E381F220220';
$stmt = $con->prepare('SELECT * FROM tb_doc_loc WHERE doc_id=? AND hp_id= ?');
$stmt->bind_param('ss',$doc_id,$hp_id);
$stmt->execute();
$res = $stmt->get_result();
while($row = $res->fetch_array()){
$data = $row['datas'];
}
$datas = explode(',',$data);
$chunk = array_chunk($datas,5);
for($i=0;$i<count($chunk);$i++): ?>
<?php if($chunk[$i][0] == $days[$i]): ?>
<tr>
<td>
<div class=" form-check" style="margin-top: 7px;">
<input class="form-check-input" type="checkbox" name="edit_days" value="<?php echo $chunk[$i][0]?>" checked="checked">
<?php echo $chunk[$i][0]?>
</div>
</td>
<td>
<div class="form-group">
<div class="row">
<div class="col-sm-6">
<label>Morning Timings</label><br>
<select class="selectpicker " id="<?php echo $chunk[$i][0]?>_Morning_time" title="Select Timings" multiple data-max-options="2" data-size="5">
<?php for($k=$startTime;$k<=$endTime;$k = $k + 30*60): ?>
<option value="<?php echo date('H:i',$k);?>"<?php if($chunk[$i][1] == date('H:i',$k) ||$chunk[$i][2] == date('H:i',$k)){echo"Selected";}?> ><?php echo date('H:i',$k)?></option>
<?php endfor; ?>
</select>
</div>
<div class="col-sm-6">
<label>Evening Timings</label><br><!-- line 73 -->
<select class="selectpicker" id="<?php echo $chunk[$i][0]?>_Evening_time" title="Select Timings" multiple data-max-options="2" data-size="5">
<?php for($k=$startTime;$k<=$endTime;$k = $k + 30*60): ?>
<option value="<?php echo date('H:i',$k);?>"<?php if($chunk[$i][3] == date('H:i',$k) ||$chunk[$i][4] == date('H:i',$k)){echo"Selected";}?> ><?php echo date('H:i',$k)?></option>
<?php endfor; ?>
</select>
</div>
</div>
</div>
</td>
</tr>
<?php endif;?>
<?php endfor;?>
<?php for($j=$i;$j<count($days);$j++): ?>
<tr>
<td>
<div class=" form-check" style="margin-top: 7px;">
<input class="form-check-input" type="checkbox" name="edit_days" value="<?php echo $days[$j]?>"><?php echo $days[$j]?>
</div>
</td>
<td>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label >Morning Start</label><br>
<select class="selectpicker " id="<?php echo $days[$j]?>_Morning_time" title="Select Timings" multiple data-max-options="2" data-size="5">
<?php for($k=$startTime;$k<=$endTime;$k = $k + 30*60): ?>
<option value="<?php echo date('H:i',$k)?>"><?php echo date('H:i',$k)?></option>
<?php endfor; ?>
</select>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label >Morning End</label><br>
<select class="selectpicker " id="<?php echo $days[$j]?>_Evening_time" title="Select Timings" multiple data-max-options="2" data-size="5" >
<?php for($k=$startTime;$k<=$endTime;$k = $k + 30*60): ?>
<option value="<?php echo date('H:i',$k)?>"><?php echo date('H:i',$k)?></option>
<?php endfor; ?>
</select>
</div>
</div>
</div>
</td>
</tr>
<?php endfor;
}
?>
output of this model:
SelectPicker is displaying when I use inspect element on the main page but problem what I find it having CSS property
.bootstrap-select > select.bs-select-hidden, select.bs-select-hidden, select.selectpicker {
display: none !important;
}
[2
why I don't know
Finally, I got the answer after reading documentation again and again that I have to call selectpicker function after displaying the Ajax output.
Ajax Call:-
$('.editModals').on('click',function(){
docId = $(this).attr('id');
$.ajax({
url:'doc_timings2.php',
data:{doc_id:docId},
type:'POST',
success:function(data){
$('#display').html(data);
$('select').selectpicker();// That's the function
}
});
I have a dropdown list with customer names from database. I want these values to be a link with my 'href' attribute. How can I do it?
<select class="feedback-input" id="customer_selecter" name="customerName">
<option >Select customer</option>
<?php foreach ($customers as $row): ?>
<a href="<?php echo base_url() . "index.php/edit/show_customer_id/" . $row->customerID; ?>">
<?php echo '<option value="'.$row->customerID.'">'.$row->customerName.'</option>'; ?></a>
<?php endforeach; ?>
</select>
try this:
<select class="feedback-input" id="customer_selecter" name="customerName">
<option >Select customer</option>
<?php foreach ($customers as $row): ?>
<a href="<?php echo base_url() . 'index.php/edit/show_customer_id/' . $row->customerID; ?>">
<option value="<?php echo $row->customerID; ?>"><?php echo $row->customerName; ?></option>
</a>
<?php endforeach; ?>
</select>
but this is not a valid html, because you're using a <a> tag inside a <select> tag, try doing this with javascript instead like this :
<select class="feedback-input" id="customer_selecter" name="customerName" onchange="location = this.value;">
<option >Select customer</option>
<?php foreach ($customers as $row): ?>
<option value="<?php echo base_url() . 'index.php/edit/show_customer_id/' . $row->customerID; ?>"><?php echo $row->customerName; ?></option>
<?php endforeach; ?>
</select>
i have two tables as shown, when employee edits its details department_id save as 0 in database
employee department
id| name|department_id id|department_name
1 |abc |1 1|HR
2 |xyz |4 2|Finance
3 |asd |3 3|Developer
and this view part
<tr>
<th> Department </th>
<td>
<SELECT name="department_id" style="width:180px;" >
<?php
foreach($departments as $row): ?>
<option value="<?php $employee['department_id'] ;?>"
<?php if ($row['id']== $stakehholder['department_id'])
{
echo 'selected';
}
?>>
<?php echo $row['department_name'];?>
</option>
<?php endforeach ?>
</SELECT>
</td>
<td> <?php echo form_error('department_id'); ?> </td>
</tr>
after edit 0 value get store in database
forget echo <option value="<?php $employee['department_id']; ?>"
<SELECT name="department_id" style="width:180px;" >
<?php foreach($departments as $row): ?>
<option value="<?php echo $row['department_id']; ?>"
<?php if ($row['department_name']== $stakehholder['department_id']) {
echo 'selected';
}
?>>
<?php echo $row['department_name']; ?>
</option>
<?php endforeach ?>
</SELECT>
updated line is in as below
<option value="<?php echo $employee['department_id'] ;?>
<tr>
<th> Department </th>
<td>
<SELECT name="department_id" style="width:180px;" >
<?php
foreach($departments as $row): ?>
<option value="<?php echo $employee['department_id'] ;?>"
<?php if ($row['department_name']== $stakehholder['department_id'])
{
echo 'selected';
}
?>>
<?php echo $row['department_name'];?>
</option>
<?php endforeach ?>
</SELECT>
</td>
<td> <?php echo form_error('department_id'); ?> </td>
</tr>
you have forgot to echo department_id in option value attribute and second you are comparing name to id which never match if id is int and name not.
try this updated code:
<SELECT name="department_id" style="width:180px;" >
<?php
foreach($departments as $row): ?>
<option value="<?php echo $row['department_id'] ;?>"
<?php if ($row['department_id']== $stakehholder['department_id'])
{
echo 'selected';
}
?>>
<?php echo $row['department_name'];?>
</option>
<?php endforeach ?>
</SELECT>
I need to modify the value and name of the products filter in a Wordpress template that I've purchased.
The template is Automotive - Templatic. I need to change values and name of filter products filter. I'm trying to change this PHP code:
<form id="search_car" name="search_car" action="<?php echo home_url(); ?>" method="get">
<input type="hidden" name="search" id="search" value="vehicle" />
<div class="selectbox select1">
<input type="text" value="<?php the_search_query(); ?>" name="s" id="s" placeholder="<?php _e('Model , Name etc...',T_DOMAIN); ?>">
</div>
<span class="shape2"><?php _e('OR',T_DOMAIN); ?></span>
<?php if($post_category): ?>
<div class="selectbox select2">
<select class="select" title="<?php _e("All Makes",T_DOMAIN); ?>" name="makes" id="makes">
<option value=""><?php _e("All Makes",T_DOMAIN); ?></option>
<?php
$args = array( 'taxonomy' => 'vcategory' );
$terms = get_terms( 'vcategory',$args);
foreach ( $terms as $term ):
?>
<option value="<?php echo $term->term_id; ?>" <?php if($_REQUEST['makes'] == $term->term_id){ ?> selected="selected" <?php } ?>><?php echo esc_attr( $term->name ); ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
<?php if($model_status): ?>
<div class="selectbox select2">
<select class="select" title="<?php _e('All Models',T_DOMAIN); ?>" name="status" id="model_status">
<option value=""><?php _e('All Models',T_DOMAIN); ?></option>
<?php
$explode = explode(",",$option);
foreach($explode as $_explode):
?>
<option value="<?php echo $_explode; ?>" <?php if($_REQUEST['status'] == $_explode){ ?> selected="selected" <?php } ?>><?php echo sprintf(__('%s',T_DOMAIN),$_explode); ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
<?php if($fuel): ?>
<div class="selectbox select2">
<select class="select" title="<?php _e('All Type',T_DOMAIN); ?>" name="fuel" id="fuel">
<option value=""><?php _e('All Type',T_DOMAIN); ?></option>
<?php
$fuel_exp = explode(",",$fuel_option);
foreach($fuel_exp as $_fuel_option):
?>
<option value="<?php echo $_fuel_option; ?>" <?php if($_REQUEST['fuel'] == $_fuel_option){ ?> selected="selected" <?php } ?>><?php echo sprintf(__('%s',T_DOMAIN),$_fuel_option); ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
I have to create 3 dropdown fields and 1 text area field. Can you help me?
Thanks in advance...
hi everyone my problem is this that i dynamically creted rows of table on the basis user input. Now each row contain textbox,comboxbox on selcting value from combobox n entering value in textbox from first three column ,result will display.on passing these selected n entered value on next page only the last row values moves to next page .i want to pass all loop values to next page
javascripting code
<script>
function getText3(row){
var in1=document.getElementById('in1-' + row).value;
var in2=document.getElementById('in2-' + row).value;
var in4=document.getElementById('in4-' + row).value;
var in3=(in1*in2*in4*30)/1000;
document.getElementById('in3-' + row).value=in3.toFixed(2 );
}
</script>
table code
<?php
$de=$_POST['text123'];
echo $de;
?>
<body>
<form action="kl2.php" method="post" >
<table border="1" align="center" id="wr123">
<tr>
<th>WAS</th>
<th>NO.</th>
<th>AVERAGE</th>
<th>APPROX</th>
</tr>
<?php
for ($i = 1; $i <= $de; $i++) {
?>
<tr>
<td>Tube</td>
<td>
<select id="in4-<?php echo $i; ?>" name="t1" onclick="getText3(<?php echo $i; ?>)" >
<option value="0">0</option>
<option value="12">12</option>
<option value="18">18</option>
<option value="24">24</option>
<option value="75">75</option>
</select>
</td>
<td>
<input type="text" name="t2" id="in1-<?php echo $i; ?>" onblur="getText3(<?php echo $i; ?>)" />
</td>
<td>
<select name="a1" id="in2-<?php echo $i; ?>" onclick="getText3(<?php echo $i; ?>)" >
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
</select>
</td>
<td>
<input type="text" id="in3-<?php echo $i; ?>" name="username" readonly="readonly" />
</td>
<td>
</tr>
<?php } ?>
<input type="submit" name="submit" />
</table>
</form>
kl2.php
<?php
#$a=$_POST['t1'];
echo #$a;
$sl = $_POST['t2'];
echo $sl;
$b=$_POST['a1'];
echo $b;
$c=$_POST['username'];
echo $c;
?>
on submit click it only display the last row values i.e if user enter 3 ,3 rows get displayed after clicking the submit only the data of last row display
You need to be passing an array, you can deal with it as an array in the PHP side.
To do this, in each input, change the name="X" to name="X[]"
Example:
<input type="text" name="t2" id="in1-<?php echo $i; ?>" onblur="getText3(<?php echo $i; ?>)" />
to:
<input type="text" name="t2[<?php echo $i; ?>]" id="in1-<?php echo $i; ?>" onblur="getText3(<?php echo $i; ?>)" />
Also, it's generally a bad idea to use #'s in php to suppress errors.
Try something like:
var_dump($_POST);
and you will see how the data comes through to you.
Hint:
if (isset($_POST['t1']) {
$t1_data = $_POST['t1'];
}
** EDIT **
Try something like this:
<?php
if (isset($_POST['submit'])) {
$data_t1 = $_POST['t1'];
foreach ($data_t1 as $key => $value) {
echo 'T1: ' . $value . '<br />';
echo 'T2: ' . $_POST['t2'][$key] . '<br />';
echo 'Username: ' . $_POST['username'][$key] . '<br /><br />';
}
}
?>
<html>
<head>
<script>
function getText3(row){
var in1=document.getElementById('in1-' + row).value;
var in2=document.getElementById('in2-' + row).value;
var in4=document.getElementById('in4-' + row).value;
var in3=(in1*in2*in4*30)/1000;
document.getElementById('in3-' + row).value=in3.toFixed(2 );
}
</script>
</head>
<body>
<form action="" method="POST">
<table border="1" align="center" id="wr123">
<tr>
<th>WAS</th>
<th>NO.</th>
<th>AVERAGE</th>
<th>APPROX</th>
</tr>
<?php
for ($i = 1; $i < 4; $i++) {
?>
<tr>
<td>Tube</td>
<td>
<select id="in4-<?php echo $i; ?>" name="t1[<?php echo $i; ?>] onclick="getText3(<?php echo $i; ?>)" >
<option value="0">0</option>
<option value="12">12</option>
<option value="18">18</option>
<option value="24">24</option>
<option value="75">75</option>
</select>
</td>
<td>
<input type="text" name="t2[<?php echo $i; ?>]" id="in1-<?php echo $i; ?>" onblur="getText3(<?php echo $i; ?>)" />
</td>
<td>
<select name="a1[<?php echo $i; ?>]" id="in2-<?php echo $i; ?>" onclick="getText3(<?php echo $i; ?>)" >
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
</select>
</td>
<td>
<input type="text" id="in3-<?php echo $i; ?>" name="username[<?php echo $i; ?>]" readonly="readonly" />
</td>
<td>
</tr>
<?php } ?>
</table>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>