How to check time overlap in bootstrap date - php

I want to check shift start time and shift time values overlapped or not. if user enter overlapped values it should prompt error. please advice
<div class="form-group">
<label for="">Shift Start:</label>
<div class='input-group date' id='datetimepicker3'>
<input type='text' name="shift_start" class="form-control"
id='datetimepicker3' value="{{old('shift_start')}}" /> <span
class="input-group-addon"> <span
class="glyphicon glyphicon-time"></span>
</span>
</div>
<div class="form-group">
<label for="">Shift End:</label>
<div class='input-group date' id='datetimepicker5'>
<input type='text' name="shift_end" class="form-control"
value="{{old('shift_end')}}" /> <span class="input-group-addon">
<span class="glyphicon glyphicon-time"></span>
</span>
</div>
</div>
this is my script
$(function () {
$('#datetimepicker3').datetimepicker({
format: 'HH:mm'
});
$('#datetimepicker5').datetimepicker({
format: 'HH:mm'
});
});

Create a javascript function :
function checkTime()
{
var start = $('#datetimepicker3').val();
var end = $('#datetimepicker5').val();
var tabStart = start.split(':');
var tabEnd = end.split(':');
var dateStart = new Date();
dateStart.setHours(parseInt(tabStart[0]));
dateStart.setMinutes(parseInt(tabStart[1]));
var dateEnd = new Date();
dateEnd.setHours(parseInt(tabEnd[0]));
dateEnd.setMinutes(parseInt(tabEnd[1]));
if(dateStart < dateEnd)
{
alert('ok');
}
else
{
alert('ko');
}
}
Then in you datetimepicker :
$(function () {
$('#datetimepicker3').datetimepicker({
format: 'HH:mm',
onSelect: function(){
checkTime();
}
});
$('#datetimepicker5').datetimepicker({
format: 'HH:mm',
onSelect: function(){
checkTime();
}
});
});

Related

How to post an Ajax onClick through a looping input form (Dinamically) from MySql query result

I would like to be suggested on how to solve an Ajax post through a looping input form (Dynamically) from MySql query result.
<?php
// Query Result
foreach ($sql->result() as $row) {
echo '
<div class="media mt-4">
<div class="media-body text-muted text-small">
<input class="d-none" value="'.$row->cY.'" name="post_X" id="post_X">
<input class="d-none" value="'.$row->cZ.'" name="post_Y" id="post_Y">
<div class="input-group">
<input style="background:#fafafa" type="text" name="post_Z" id="post_Z" placeholder="Join conversation here..." class="form-control">
<div class="input-group-append">
<button type="button" onclick="addPost()" class="btn btn-outline-secondary"><i class="fa fa-send"></i></button>
</div>
</div>
</div>
</div>';
}
?>
Ajax script
<script>
function addPost() {
if(!$("#post_Z").val()) {
// An Alert!
} else {
var post_X = $("#post_X").val();
var post_Y = $("#post_Y").val();
var post_Z = $("#post_Z").val();
$.post("reply.php", {
uid: post_X,
cid: post_Y,
txt: post_Z
}, function (data, status) {
// An Alert!
});
};
}
</script>
Thanks alot
give an id for each iteration, and add the id in the addPost event so that the post only retrieves data according to the id that is defined
change the code to be like this
<?php
// Query Result
$uniq = 1;
foreach ($sql->result() as $row) {
echo '
<div class="media mt-4">
<div class="media-body text-muted text-small">
<input class="d-none" value="'.$row->cY.'" name="post_X_'.$uniq.'" id="post_X_'.$uniq.'">
<input class="d-none" value="'.$row->cZ.'" name="post_Y_'.$uniq.'" id="post_Y_'.$uniq.'">
<div class="input-group">
<input style="background:#fafafa" type="text" name="post_Z_'.$uniq.'" id="post_Z_'.$uniq.'" placeholder="Join conversation here..." class="form-control">
<div class="input-group-append">
<button type="button" onclick="addPost('.$uniq.')" class="btn btn-outline-secondary"><i class="fa fa-send"></i></button>
</div>
</div>
</div>
</div>';
$uniq++;
}
?>
and the ajax
<script>
function addPost(id) {
if(!$("#post_Z_"+id).val()) {
// An Alert!
} else {
var post_X = $("#post_X_"+id).val();
var post_Y = $("#post_Y_"+id).val();
var post_Z = $("#post_Z_"+id).val();
$.post("reply.php", {
uid: post_X,
cid: post_Y,
txt: post_Z
}, function (data, status) {
// An Alert!
});
};
}
</script>
may these help

Activate JS functionality on clone two inputs fields

i have a form with various fields, and a pair of buttons of clone and remove the cloned part of the form.
Also, i have in those fields a pair of inputs of integers that when i click in one of them
the value "jump" to the other field when clicked.
The problem is when i clone the form the functionality of "jump" do not attach to the other cloned inputs.
this is the clone function :
var regex = /^(.+?)(\d+)$/i;
var cloneIndex = 1;//$(".clonedInput").length;
function clone(){
cloneIndex++;
$(this).parents(".clonedInput").clone()
.appendTo("form")
.attr("id", "clonedInput" + cloneIndex)
.find("*")
.each(function() {
var id = this.id || "";
var match = id.match(regex) || [];
if (match.length == 3) {
this.id = match[1] + (cloneIndex);
//console.log(this.val);
//this.value = $(match).val();
//console.log("El valor seleccionado es ");
//this.val = match[1].val;
}
})
.on('click', 'button.clone', clone)
.on('click', 'button.remove', remove);
return false;
}
function remove(){
if($('.actions').length == 2){
console.log('accion cancelada');
}else{
$(this).parents(".clonedInput").remove();
}
return false;
}
$("button.clone").on("click", clone);
$("button.remove").on("click", remove);
an approach to this was made with this code using dinamicaly for php
$("input[id^='montoa']").on("click", function(e){
var montoa_id = this.id;
var montob_id = 'montob'+montoa_id.match(/(\d+)/g)[0];
$('#'+montoa_id).value = $('#'+montob_id).val();
$('#'+montob_id).value = '';
});
the inputs are this :
<div class="col-md-1">
<input type="text" name="monto[]" class="form-control" id="montoa1" placeholder="Debe">
</div>
<div class="col-md-1">
<input type="text" name="monto[]" class="form-control" id="montob1" placeholder="Haber">
</div>
and all the n-cloned fields are numbered by auto-increase the id like id="montoa2" and id="montob3" and so on.
all comments wil be very appreciated.
EDIT : Create a jsfiddle https://jsfiddle.net/o63c61sj/
today solved !
This time was add a param to a .clone() function
This because this is a deepWithDataAndEvent clonation event as jquery says.
.clone( [withDataAndEvents ] [, deepWithDataAndEvents ] )
The solution this time for me was clone(true).
Hope someone else could be useful. `
$(document).ready(function() {
$("input[id^='montoa']").attr("placeholder", "dollars");
$("input[id^='montob']").attr("placeholder", "dollars");
$("#montoa1").on('click', function() {
var montoa = $('#montoa1').val();
$('#montoa1').val($('#montob1').val());
$('#montob1').val(0);
});
$("#montob1").on('click', function() {
var montoa = $('#montoa1').val();
$('#montoa1').val(0);
$('#montob1').val(montoa);
});
}
/*
$("input[id^='montoa']").on("click", function(e){
var montoa_id = this.id;
var montob_id = 'montob'+montoa_id.match(/(\d+)/g)[0];
$('#'+montoa_id).value = $('#'+montob_id).val();
$('#'+montob_id).value = '';
});
$("input[id^='montob']").click(function(){
console.log(this.id);
});
*/
);
var regex = /^(.+?)(\d+)$/i;
var cloneIndex = 1; //$(".clonedInput").length;
function clone() {
cloneIndex++;
$(this).parents(".clonedInput").clone(true)
.appendTo("form")
.attr("id", "clonedInput" + cloneIndex)
.find("*")
.each(function() {
var id = this.id || "";
var match = id.match(regex) || [];
if (match.length == 3) {
this.id = match[1] + (cloneIndex);
}
})
.on('click', 'button.clone', clone)
.on('click', 'button.remove', remove);
return false;
}
function remove() {
if ($('.actions').length == 2) {
console.log('accion cancelada');
} else {
$(this).parents(".clonedInput").remove();
}
return false;
}
$("button.clone").on("click", clone);
$("button.remove").on("click", remove);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form action="#" method="post">
<div id="clonedInput1" class="clonedInput">
<div class="form-group row">
<div class="actions">
<div class="panel-group">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="actions">
<button class="clone btn btn-success">Duplicar</button>
<button class="remove btn btn-warning">Quitar</button>
</div>
</div>
<div class="panel-body">
<div class="form-group row">
<div class="col-md-2">
same js functions on all cloned
</div>
<div class="col-md-1">
<input type="text" name="monto[]" class="form-control" id="montoa1" placeholder="Debe">
</div>
<div class="col-md-1">
<input type="text" name="monto[]" class="form-control" id="montob1" placeholder="Haber">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
`

Angular JS md-datepicker

I want to insert my md-datepicker value into PHP database but while inserting the error is that the data is undefined, in case of Date. How should I insert the value of md-datepicker inside the PHP Page.
reservation.html
<div id="reservation" class="reservation" ng-controller="ReservationController">
<h2><i>Reservations</i></h2>
<div class="datepicker" ng-controller="DatePickerController">
<section layout="row" layout-sm="column" layout-align="center center" layout-wrap required>
<md-datepicker ng-model="ctrl.myDate" md-placeholder="Enter Date" md-open-on-focus required></md-datepicker>
</div>
<input type='text' class='myBox' placeholder="Enter your name..." ng-model="username">
<input type='text' class='myBox' style="margin-left:100px;" placeholder="Enter your mobile number..." ng-model="mobile_number">
<div class="book">
<button type="submit" class="btn btn-primary btn-lg" ng-click="insertData()">Book Your Meal</button>
</div>
</div>
datepicker.js
app.controller('DatePickerController',['$scope',function($scope){
this.myDate = new Date();
var [] newDate = ctrl.MyDate.Split(T);
string finalDate = newdate[0];
$scope.myDate = finalDate;
this.isOpen = false;
}]);
reservation.js
app.controller("ReservationController",['$scope', '$http', function ($scope,$http) {
$scope.insertData = function(){
//window.location.href='index.html#/menu';
$http.post('database/push_Reservation.php',{'username':$scope.username, 'mobile_number': $scope.mobile_number, 'mydate': $scope.myDate})
.then(function(data){
console.log(data);
});
}
}]);
DatepickerController:
app.controller('DatePickerController',['$scope',function($scope){
this.myDate = new Date();
var [] newDate = ctrl.MyDate.Split(T);
string finalDate = newdate[0];
$scope.myDate = finalDate;
this.isOpen = false;
$scope.$emit('response', $scope.myDate);
}]);
ReservationController:
app.controller("ReservationController",['$scope', '$http', function ($scope,$http) {
$scope.$on('response', function (evnt, data) {
$scope.myDate = data;
});
$scope.insertData = function(){
//window.location.href='index.html#/menu';
$http.post('database/push_Reservation.php',{'username':$scope.username, 'mobile_number': $scope.mobile_number, 'mydate': $scope.myDate})
.then(function(data){
console.log(data);
});
}
}]);

subtract the given age into the current date

I have two fields where one field is used to give input of user age and another field to display the date of birth as per current date.
My html code is:-
<div class="col-xs-4 form-group">
<label><?php echo _('DOB'); ?> : </label>
<input value="" type="text" name="jbs_dob" id="jbs_dob" size="17" />
</div>
<div class="col-xs-4 form-group">
<label><?php echo _('Age'); ?> : </label>
<input value="" class="validate[required] form-control" type="text" name="jbs_age" id="jbs_fname" size="17" />
</div>
My js and jquery code is:
$(function () {
$("#jbs_age").click(function () {
var jbs_dob = new Date();
var jbs_age =$('jbs_age').val();
var diff= jbs_dob-jbs_age;
$( "#jbs_dob" ).html(diff);
});
});
Try below code. This will return you Year of the birth. If you provide age 25 then it will show 1991 in birth day field.
$(function () {
$("#jbs_age").click(function () {
var jbs_dob = new Date();
var jbs_age =$('#jbs_age').val();
var age = (jbs_dob.getFullYear() - jbs_age);
$( "#jbs_dob" ).val(age);
});
});

select box validation

below is the code for selectbox validation but it is not working..can anybody help please..
<?php include('../config.php'); ?>
<style>
#errorMessage {
color:red;
font-size:12px;
margin-left:10px;
}
</style>
</form>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"> </script>
<script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"> </script>
<script>
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$( "#agentlist" ).validate({
rules: {
field: {
required: true
}
}
});
</script>
<div id="distanceform" style="width:100%; height:auto;border:0.1em solid #CCC;float:left;">
<div id="distanceformtitle" style="border-bottom:0.1em solid #CCC;width:98%;height:25px;text-align:left;font-size:13px;padding-left:2%;padding-top:11px;background-color:#FAFAFA;color:#1D89CE;">Distance Report</div>
<div id="errorMessage"></div>
<span>
<select name="agentlist" id="agentlist" class="selectclass">
<option value="">--Select Agent--</option>
<?php
$x=mysqli_query($con,"select * from accounts where gid='0' and companyid='".$_SESSION['newforcecid']."' and publishstatus='1'");
while($data=mysqli_fetch_assoc($x)){
?>
<option value="<?php echo($data['imeino']); ?>">
<?php echo($data['firstname']); ?></option><?php
}
?>
</select>
</span>
<span><input type="text" class="textclass" name="fromdate" id="fromdate" placeholder="From Date" value="<?php echo(date('d-m-Y')); ?>"></span>
<span><input type="text" class="textclass" name="todate" id="todate" placeholder="To Date" value="<?php echo(date('d-m-Y')); ?>"></span>
<input type="button" id="search" name="search" value="Search" class="btnclass">
</div>
<br>
<div id="distanceresult" >
</div>
validation is not working..when i click on submit data is not gettng displayed and at same time error msg is also not gettng displayed
Just you need to add the dateFormat: 'dd-mm-yy', after number of months
Check Demo here
<script>
$(function () {
$("#txtFrom").datepicker({
numberOfMonths: 1,
dateFormat: 'dd-mm-yy',
onSelect: function (selected) {
var dt = new Date(selected);
dt.setDate(dt.getDate() + 1);
$("#txtTo").datepicker("option", "minDate", dt);
}
});
$("#txtTo").datepicker({
numberOfMonths: 1,
dateFormat: 'dd-mm-yy',
onSelect: function (selected) {
var dt = new Date(selected);
dt.setDate(dt.getDate() - 1);
$("#txtFrom").datepicker("option", "maxDate", dt);
}
});
});
</script>
You can use dateFormat:"dd-mm-yy" in the options. Please do check out all the possible dateFormats Here
Assuming that you are using jQuery-ui:
var date=$.datepicker.formatDate( "dd-mm-yy", new Date( 2015, 2 - 1, 25 ) );
Value of date will be: 2015-02-25

Categories