Select Picker Is Not Showing When i call Using Ajax - php

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
}
});

Related

Repetitive form control

Vs code
Output
<div class="form-group">
<label class="control-label col-lg-4" for="username">Menu</label>
<div class="col-lg-8">
<select class="form-control select2 " id="exampleSelect1" name="menu[]" multiple='multiple' style="width: 100%;height:200px" placeholder="Select multiple members">
<?php
$m = mysqli_query($con,"SELECT * FROM combo_details natural join menu where combo_id='$id'");
while ($rowm = mysqli_fetch_assoc($m)){
?>
<option selected value="<?php echo $rowm['menu_id'];?>"><?php echo $rowm['menu_name'];?></option>
<?php
}
?>
<?php
$result = mysqli_query($con,"SELECT * FROM menu");
while ($row = mysqli_fetch_assoc($result)){
?>
<option value="<?php echo $row['menu_id'];?>"><?php echo $row['menu_name'];?></option>
<?php
}
?>
</select>
</div>
</div>
tried changing selected value and i even tried to delete it and merge it but it doesnt work. need help

how to insert data in database using dropdown with foreach loop

here i am creating a attendance sheet that insert data into the database
after clicking submit button. The insertion of the data is base on the 2
radio button which is absent/present, the problem is after clicking submit
button the other component works accordingly except for the dropdown button,
the dropdown button insert only a single string instead of the service time
by the way i declare the service time in the database as varchar so i am
confident that it's not the database that causes the error. maybe someone
can help me any help is much appreciated. thank you in advance
enter code here
<?php
include("Sampledb.php");
include("Sample.php");
$flag=0;
if(isset($_POST['submit']))
{
foreach($_POST['attendance_status'] as $id1=>$attendance_status)
{
$name=$_POST['name'][$id1];
$id=$_POST['id'][$id1];
$date=date("Y-m-d H:i:s");
$servicetime=$_POST['servicetime'][$id1];
$result=mysqli_query($objconn,"insert into
attendrecord(id,name,attendance_status,attendance_date,servicetime)
values('$id','$name','$attendance_status','$date','$servicetime')");
if($result)
{
$flag=1;
}
}
header("Location:sampleindex.php");
exit;
}
?>
<div class="panel panel-default">
<div class="panel panel-heading">
<form action="sampleindex.php" method="Post">
<label>Service time:</label>
<select name="servicetime">
<option>00:00</option>
<option value="7:30-9:30">7:30-9:30</option>
<option value="10:30-12:30">10:30-12:30</option>
<option value="1:30-3:30">1:30-3:30</option>
<option value="4:30-6:30">4:30-6:30</option>
</select>
<a class="btn btn-info pull-right" href="view.php">View all<a/>
</div>
</div>
<div id="alert" style="display:none;" class="alert alert-success" ">
×
<strong>Success!</strong>Save
</div>
<h3>
<div class="well text-center">Date:<?php echo date("Y-m-d"); ?> </div>
</h3>
<div class="panel panel-body">
<tr>
<table class="table table-striped">
</tr>
<th>ID Number</th><th>Member Name</th><th>Attendace Status</th>
<?php $result=mysqli_query($objconn,"select* from attend");
$id = 0;
$counter=0;
while($row=mysqli_fetch_array($result))
{
$id++;
?>
<tr>
<td><?php echo $row['id']; ?></td>
<input type="hidden" value="<?php echo $row['id']; ?>"name="id[]">
<td><?php echo $row['name']; ?></td>
<input type="hidden" value="<?php echo $row['name']; ?>"name="name[]">
<td>
<input type="radio" name="attendance_status[<?php echo $counter; ?>]"
value="present">Present
<input type="radio" name="attendance_status[<?php echo $counter; ?>]"
value="absent">Absent
</td>
</tr>
<?php
$counter++;
}
?>
</table>
<input type="submit" name="submit" value="submit" onclick="return mess();">
</div>
<script type="text/javascript">
function mess()
{
if($flag=1){
alert ("Record Save!");
return true;}
else
alert ("Record Not Save!");
}
</script>
<script type="text/javascript">
$(document).ready(function(){
$('#submit').click(function(){
$('#alert').css('display','block');
});
});
</script>
</div>
</div>
Your service time is not an array as it keeps same for all record. So you need to change your PHP code as below:
$servicetime=$_POST['servicetime'];
Hope it helps you.
Instead of $_POST['servicetime'][$id] use $_POST['servicetime']

Why I can't use chained jquery in loop condition?

<?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/

Refinement bar with multiple options submitted

I am trying to create a refinement bar with multiple filter options submitted in the form. Currently I have the form just submitting one option, can someone please tell me what I am missing in my code?
<form action="" method="post">
<div id="box">
<p>Occasion:</p>
<?php
$rs=mysql_query('select DISTINCT occasion from cakes');
?>
<select name="occasion"onchange='location=this.options[this.selectedIndex].value;'>
<?php
$path="filter1.php?search=";
while($record=mysql_fetch_assoc($rs)){
?>
<option value="<?php echo $path.$record['occasion']; ?>"><?php echo $record['occasion']; ?></option>
<?php
}
?>
</select>
</div>
<div id="box">
<p>Styles:</p>
<?php
$rs=mysql_query('select DISTINCT style from cakes');
?>
<select name="style" onchange='location=this.options[this.selectedIndex].value;'>
<?php
$path="filter1.php?choice=";
while($record=mysql_fetch_assoc($rs)){
?>
<p><option value="<?php echo $path.$record['style']; ?>"><?php echo $record['style']; ?></option></p>
<?php
}
?>
</select>
</div>
<div id="box">
<p>Colours:</p>
<?php
$rs=mysql_query('select DISTINCT colour from cakes');
?>
<select name="colour" onchange='location=this.options[this.selectedIndex].value;'>
<?php
$path="filter1.php?choice=";
while($record=mysql_fetch_assoc($rs)){
?>
<p><option value="<?php echo $path.$record['colour']; ?>"><?php echo $record['colour']; ?></option></p>
<?php
}
?>
</select>
</div>
<div id="box">
<p>Filling:</p>
<?php
$rs=mysql_query('select DISTINCT filling from cakes');
?>
<select name="filling"
onchange='location=this.options[this.selectedIndex].value;' >
<?php
$path="filter1.php?choice=";
while($record=mysql_fetch_assoc($rs)){
?>
<p><option value="<?php echo $path.$record['filling']; ?>"><?php echo $record['filling']; ?></option></p>
<?php
}
?>
</select>
<p>
</div>
<div id="box">
<p>Topping:</p>
<?php
$rs=mysql_query('select DISTINCT topping from cakes');
?>
<select name="topping"
onchange='location=this.options[this.selectedIndex].value;' >
<?php
$path="filter1.php?choice=";
while($record=mysql_fetch_assoc($rs)){
?>
<p><option value="<?php echo $path.$record['topping']; ?>"><?php echo $record['topping']; ?></option></p>
<?php
}
?>
</select>
<p>
</div>
</form>

Displaying Related Attributes when i select a Category from the dropdown list?

I want to display the Attributes based on selection from the dropdown list.For this i wrote some code it is working fine in local(out side the Magento),Now i want to work it out in side the magento....I am using Magento CE 1.7
this is my code (out side magento code)
Local code :-
<html>
<head>
<title></title>
</head>
<body>
<select id="xyz">
<option value="Men">Men</option>
<option value="Women">Women</option>
<option value="Kids">Kids</option>
<option value="Furniture">Furniture</option>
<option value="Books">Books</option>
</select>
<div id="Men" class="group">
Color<input id="color" name="color" type="text">
Size<input id="size" name="size" type="text">
</div>
<div id="Women" class="group">
Size<input id="size" name="size" type="text">
</div>
<div id="Kids" class="group">
Color<input id="color" name="color" type="text">
</div>
<div id="Furniture" class="group">
Color<input id="color" name="color" type="text">
Size<input id="size" name="size" type="text">
Finishing<input id="finishing" name="finishing">
</div>
<div id="Books" class="group">
ISBN<input id="isbn" name="isbn" type="text">
</div>
</body>
<script language="JavaScript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script language="JavaScript" type="text/javascript">
$(document).ready(function () {
$('.group').hide();
$('#Men').show();
$('#xyz').change(function () {
$('.group').hide();
$('#'+$(this).val()).show();
})
});
</script>
</script>
</html>
Yeah Now i want to apply same thing in magento Dropdown Categories for this i wrote this code But its not working Why ? Anything wrong i did ?
Magento Code:-
<tr>
<td class="tdpadfirst">
<label for="category" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Product Category') ?>:</label><span class="required starimp"> </span>
</td>
<td class="tdpadsec">
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<select id="xyz" class="myinput-text required-entry widthinput" name="category">
<option value="">--Select Categories--</option>
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<element onclick="<?php $currentCategory = Mage::registry('current_category') ?>">
<?php if (count($_categories) > 0): ?>
<?php foreach($_categories as $_category): ?>
<option value="<?php echo $_category->getId() ?>">
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?></a>
</option>
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
</td>
<div id="Mens" class="group">
<tr>
<td class="tdpadfirst">
<label for="size" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Size') ?> :</label><span class="required starimp"> </span>
</td>
<td class="tdpadsec">
<input type="size" class="required-entry widthinput" name="size" id="size" value="<?php echo $size ?>"/>
<?php echo Mage::helper('marketplacepartner')->__('For multiple values separate with , (Example: 10,20) ') ?>
</td>
</tr>
<tr>
<td class="tdpadfirst">
<label for="seller_colour" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Color') ?> :</label><span class="required starimp"> </span>
</td>
<td class="tdpadsec">
<input type="seller_colour" class="required-entry widthinput" name="seller_colour" id="seller_colour" value="<?php echo $seller_colour ?>"/>
<?php echo Mage::helper('marketplacepartner')->__('For multiple values separate with , (Example: White,Black) ') ?>
</td>
</tr>
</div>
<div id="Womens" class="group">
<tr>
<td class="tdpadfirst">
<label for="size" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Size') ?> :</label><span class="required starimp"> </span>
</td>
<td class="tdpadsec">
<input type="size" class="required-entry widthinput" name="size" id="size" value="<?php echo $size ?>"/>
<?php echo Mage::helper('marketplacepartner')->__('For multiple values separate with , (Example: 10,20) ') ?>
</td>
</tr>
</div>
<div id="Kids" class="group">
<tr>
<td class="tdpadfirst">
<label for="seller_colour" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Color') ?> :</label><span class="required starimp"> </span>
</td>
<td class="tdpadsec">
<input type="seller_colour" class="required-entry widthinput" name="seller_colour" id="seller_colour" value="<?php echo $seller_colour ?>"/>
<?php echo Mage::helper('marketplacepartner')->__('For multiple values separate with , (Example: White,Black) ') ?>
</td>
</tr>
</div>
<div id="furniture" class="group">
<tr>
<td class="tdpadfirst">
<label for="seller_colour" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Color') ?> :</label><span class="required starimp"> </span>
</td>
<td class="tdpadsec">
<input type="seller_colour" class="required-entry widthinput" name="seller_colour" id="seller_colour" value="<?php echo $seller_colour ?>"/>
<?php echo Mage::helper('marketplacepartner')->__('For multiple values separate with , (Example: White,Black) ') ?>
</td>
</tr>
</div>
<script language="JavaScript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('.group').hide();
$('#Mens').show();
$('#category').change(function () {
$('.group').hide();
$('#'+$(this).val()).show();
})
});
</script>
</script>
Here i am Using Magento CE 1.7
any Ideas ?
seems your layout is clumsy,
<div id="Kids" class="group">
<tr>
<td class="tdpadfirst">
<label for="seller_colour" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Color') ?> :</label><span class="required starimp"> </span>
</td>
<td class="tdpadsec">
<input type="seller_colour" class="required-entry widthinput" name="seller_colour" id="seller_colour" value="<?php echo $seller_colour ?>"/>
<?php echo Mage::helper('marketplacepartner')->__('For multiple values separate with , (Example: White,Black) ') ?>
</td>
</tr>
</div>
Im not sure how could you place <tr> inside a <div> tag?, please re organize them in div structure
<table>
<tr><td>
your category divs
</td>
</tr>
</table>

Categories