jQuery ui Slider value not reading - jquery-ui-slider

I created value slider with jQuery.
<div class="specialSearch">
<form action="#" method="GET">
<script type="text/javascript">
$(function() {
$( "#juiSlideIMDB" ).slider({
value: 7.0,
min: 0.0,
max: 9.9,
step: 0.1,
slide: function(event,ui){
$(".specialSearch form div b").val(ui.value);
}
});
$(".specialSearch form div b").val($("#juiSlideIMDB").slider("value"));
});
</script>
<div>IMDB Vote: <b></b></div>
<div id="juiSlideIMDB"></div>
</form>
</div>
This code, specialSearch form div b value doesn't change. But, this line:
$(".specialSearch form div b").val($("#juiSlideIMDB").slider("value"));
to
$(".specialSearch form div b").text($("#juiSlideIMDB").slider("value"));
val -> text not in the current. So, changing once. It for the first value.
Slider tries values(.specialSearch form div b) ​​change.
How do we do?
Thank you for your interest.

I am solved. Thanks..
<div class="specialSearch">
<form action="#" method="GET">
<script type="text/javascript">
$(function() {
$( "#juiSlideIMDB" ).slider({
value: 7.0,
min: 0.1,
max: 9.9,
step: 0.1,
slide: function(event,ui){
$("#imdbVote").val(ui.value);
}
});
$("#imdbVote").val($("#juiSlideIMDB").slider("value"));
});
</script>
<div>IMDB Vote: <input readonly="readonly" type="text" id="imdbVote" /></div>
<div id="juiSlideIMDB"></div>
</form>
</div>
imdbVote css;
#imdbVote{position:absolute;border:0;color:#f6931f;font-weight:bolder;width:25px;}

Related

Fancybox to open on link click only first time then go to page url

I'm trying to gate a link using fancybox and cookies to show a form the first time the link is clicked and then once the form is submitted the popup form would no longer pop up but instead would open to the page url. Here is my code but so far all I can do is get the popup form to show on link click. How do I tell fancybox to not show if the cookie is present and instead go to a page link?
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title></title>
<link href="http://intercross2.com/CPS_landing_page/assets/fancybox/dist/jquery.fancybox.min.css" rel="stylesheet" />
</head>
<body>
<a class="fancybox" data-fancybox data-src="#donation-info" href="thankyou.html" alt="">Fancybox</a>
<div style="display:none">
<div id="donation-info">
<h2>Answer a few short questions to continue</h2>
<form id="gate" method="post" action="sendmail.php">
<label for="name">Your Name</label><br>
<input type="text" name="name" title="Enter your name" class="required"><br>
<label for="phone">Daytime Phone</label><br>
<input type="tel" name="phone" class="required"><br>
<label for="email">Email</label><br>
<input type="email" name="email" title="Enter your e-mail address" class="required email"><br>
<input type="submit" name="submit" class="submit-link" id="submit" value="Submit" />
</form>
</div>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="http://intercross2.com/CPS_landing_page/assets/fancybox/dist/jquery.fancybox.min.js"></script>
<script>
$(function () {
// Define cookie name
var cookieName = 'hide_form';
// Configure fancyBox
$('.fancybox').fancybox({
autoDimensions: false,
autoSize: false,
height: 'auto',
padding: 20,
width: 650,
afterClose: function() {
// Set cookie to hide fancybox for 1 day
$.cookie(cookieName, true, { expires: 1 });
}
});
// Handle submit click event
$('a#submit').on('click', function (event) {
event.preventDefault();
// Hide fancybox and set cookie to hide fancy box for 7 days
$.fancybox.close();
$.cookie(cookieName, true, { expires: 7 });
});
</script>
</body>
</html>
If you need to do check if cookie exists, then use something like:
if (!!$.cookie(cookieName)) { /* Open fancyBox here */ }
The rest is up to you.

Make a bootstrap datepicker from a pop-up to inline

I used this datepicker and it works fine, but I can't find how to display the contents of this datepicker in a <div> without the pop.
My code:
<div id="datepicker" class="input-group date" data-date-format="dd-mm-yyyy">
<input class="form-control" type="text" readonly />
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
<script type="text/javascript">
jQuery(function () {
jQuery("#datepicker").datepicker({
startDate: new Date(),
minDate: 0,
language: "fr",
autoOpen: true,
autoclose: true,
todayHighlight: true
}).datepicker('update', new Date());
});
</script>
EDIT:
I can't get the value date from the input
<div id="datepicker" class="input-group date" data-date-format="dd-mm-yyyy"></div>
<input type="hidden" id="my_hidden_input" class="form-control">
<script type="text/javascript">
jQuery('#datepicker').datepicker();
jQuery('#datepicker').on('changeDate', function() {
jQuery('#my_hidden_input').val( jQuery('#datepicker').datepicker('getFormattedDate'));
});
jQuery(document).ready(function () {
jQuery("#datepicker").datepicker({
startDate: new Date(),
language: "fr",
autoOpen: true,
autoclose: true,
todayHighlight: true
//datesDisabled: ['22/02/2017', '28/02/2017']
}).datepicker('update', new Date());;
});
jQuery("input[type=hidden]").bind('change', function() {
alert(jQuery(this).val());
});
</script>
As the docs say:
Instantiating the datepicker on a simple div will give an embedded picker that is always visible.
Here a working sample:
jQuery(function () {
jQuery("#datepicker").datepicker({
startDate: new Date(),
minDate: 0,
language: "fr",
autoOpen:true,
autoclose: true,
todayHighlight: true
}).datepicker('update', new Date());
jQuery('#datepicker').on('changeDate', function(e) {
jQuery('#my_hidden_input').val(e.date);
});
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker3.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/locales/bootstrap-datepicker.fr.min.js"></script>
<div id="datepicker" class="input-group date" data-date-format="dd-mm-yyyy">
</div>
<input type="hidden" id="my_hidden_input" class="form-control">
EDIT:
You are adding the the changeDate listner in the wrong place, put it after datepicker initialization. Moreover changeDate event has the date property that contains Date object representing the selected date.

Passing a static selected list to different textboxes

<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>list</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>var split="Grand Hotel,Promenade,Southend,Postcode".split(',');
var hotel=split[0];
var street=split[1];
var town=split[2];
var postcode=split[3]
</script>
</script>
<script>var split="Imperial Hotel,Main St,Dundee,Postcode".split(',');
var hotel=split[0];
var street=split[1];
var town=split[2];
var postcode=split[3]
</script>
<script>
$(document).ready(function () {
$('li').click(function () {
console.log($(this).text());
$('#hotel').val($(this).text());
});
}
);
</script>
<style>
.ui-menu { width: 250px; }
</style>
<script>
$(function() {
$( "#menu" ).menu();
});
</script>
<style>
.ui-menu { width: 250px; }
</style>
</head>
</body>
<body>
<div id="locationselect">
<ul>
<li>Grand Hotel,Promenade,Southend,Postcode</li>
<p>
<li>Imperial Hotel,Main St,Dundee,Postcode</li>
<p>
</ul>
</div>
<input type="text" id="split[0]"/>
<p>
<input type="text" id="split[1]"/>
<p>
<input type="text" id="split[2]"/>
<p>
<input type="text" id="split[3]"/>
<p>
</body>
</html>
I knew nothing about coding until I joined a coarse two weeks ago and have got a bit ahead of myself lol but i'm really enjoying the problem solving in working things out, i've got far too much time on my hands. I'm trying to work out a way of selecting and splitting a static list and then passing this into seperate textboxes. Any help would be very much appreciated, I have looked and as far as I can tell i'm the first to ask this specific question, woo hoo!!
<script>
$(document).ready(function () {
$('.selectableItem').click(function () {
//alert('txt=' + $(this).text());
var selected = $(this).text().split(",");
console.log(selected);
$('#location').val(selected[0]);
$('#location2').val(selected[1]);
$('#location3').val(selected[2]);
$('#location4').val(selected[3]);
});
}
);
</script>

Ember.js - CollectionView, add an attribute to the div wrapper of the child view

I'm trying to combine two ebmer.js examples: Integrating with jQuery UI and the todos example from emberjs.com. I want to have a todo list that is sortable.
Everything went smooth until I got to a point where I wanted to serialize the sortable. For that to work, I need to be able to add an attribute to the sortable items.
this is the template:
{{#collection Todos.TodosListView}}
{{#view Todos.TodoView contentBinding="content" checkedBinding="content.isDone"}}
<label>{{content.title}}</label>
{{/view}}
{{/collection}}
Todos.TodosListView is a CollectionView, similar to the menu in the jQuery UI example. Todos.TodoView is a Checkbox.
This generates the following html:
<div class="ember-view todo-list ui-sortable" id="ember267">
<div class="ember-view" id="ember284">
<input type="checkbox" class="ember-view ember-checkbox todo" id="ember297">
<label>
<script type="text/x-placeholder" id="metamorph-1-start"></script>
something to do
<script type="text/x-placeholder" id="metamorph-1-end"></script>
</label>
</div>
</div>
What I need to be able to do is edit the <div> that wraps the <input>. Assuming the todo's id is 1, I want to add serial=todos_1. I tried to add didInsertElement to TodoView and add an attribute to the parent view, but I didn't have access to the content of the view (the todo itself).
Is this possible?
Thanks for your help.
EDIT:
I found a workaround - adding the ID to the DOM as a hidden element.
The updated template:
{{#collection Todos.TodosListView}}
{{#view Todos.TodoView contentBinding="content" checkedBinding="content.isDone" serial="content.serial"}}
<label>{{content.title}}</label>
<span style="display: none;" class="todo-id">{{content.id}}</span>
{{/view}}
{{/collection}}
Todos.TodoView.didInsertElement:
didInsertElement: function() {
var $div = this.get('parentView').$();
var id = $div.children('.todo-id').text();
$div.attr('serial', 'todos_' + id);
}
Generated html:
<div class="ember-view todo-list ui-sortable" id="ember267">
<div class="ember-view" id="ember284" serial="todos_100">
<input type="checkbox" class="ember-view ember-checkbox todo" id="ember297">
<label>
<script type="text/x-placeholder" id="metamorph-1-start"></script>
something to do
<script type="text/x-placeholder" id="metamorph-1-end"></script>
</label>
<span class="todo-id" style="display: none;">
<script type="text/x-placeholder" id="metamorph-2-start"></script>
100
<script type="text/x-placeholder" id="metamorph-2-end"></script>
</span>
</div>
</div>
I would still like to know if there's a more elegant way of achieving this.
You can create a computed property serial and add this property to the attributeBindings (documented here) of your itemViewClass of Todos.TodosListView, see http://jsfiddle.net/pangratz666/6X4QU/:
Todos.TodosListView = Ember.CollectionView.extend({
itemViewClass: Ember.View.extend({
attributeBindings: ['serial'],
serial: function() {
return 'todos_' + Ember.getPath(this, 'content.id');
}.property('content.id').cacheable()
})
});

Knockout.js Template not updating UI binding on a dependantObservable

The application is written using ASP.NET MVC 3 in vs2010.
I have a knockout template that updates some css and visible bindings using a
dependantObservable.
The issue ONLY occurs when I bind the
value of the select element to the
IntervalID. If this is not bound the
UI is updated as expected.
I have ripped the code out from my main app and created a sample page that does the same binding using standard markup and also templates.
The dependantObservable is called HasChanged.
<script src="#Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="../../Scripts/jquery.tmpl.js" type="text/javascript"></script>
<script src="../../Scripts/knockout-1.2.0.js" type="text/javascript"></script>
<div data-bind="template: { name: 'intervalTemplate', for:viewModel }">
</div>
<h2>
Not Template</h2>
<div data-bind="style: { color: HasChanged() ? 'red' : 'black' }">
IntervalID: <span data-bind="text: IntervalID"></span>
<br />
Start:
<input type="text" data-bind="value: Start">
<br />
End:
<input type="text" data-bind="value: End">
<br />
Interval Type:
<select data-bind="value: IntervalTypeID">
<option value="1">Shift</option>
<option value="2">Break (Paid)</option>
<option value="3">Break (Unpaid)</option>
</select><br />
HasChanged: <span data-bind="text: HasChanged"></span>
</div>
<script id="intervalTemplate" type="text/html">
<div data-bind="style: { color: HasChanged() ? 'red' : 'black' }">
<h2>Template</h2>
IntervalID: <span data-bind="text: IntervalID"></span>
<br />
Start:
<input type="text" data-bind="value: Start">
<br />
End:
<input type="text" data-bind="value: End">
<br />
Interval Type:
<select data-bind="value: IntervalTypeID">
<option value="1">Shift</option>
<option value="2">Break (Paid)</option>
<option value="3">Break (Unpaid)</option>
</select><br />
HasChanged: <span data-bind="text: HasChanged"></span>
</div>
</script>
<script type="text/javascript">
function IntervalModel(data) {
var _this = this;
_this.IntervalID = ko.observable(data.IntervalID);
_this.Start = ko.observable(data.Start);
_this.End = ko.observable(data.End);
_this.IntervalTypeID = ko.observable(data.IntervalTypeID);
_this.OriginalStart = ko.observable(data.Start);
_this.OriginalEnd = ko.observable(data.End);
_this.OriginalIntervalTypeID = ko.observable(data.IntervalTypeID);
_this.HasChanged = ko.dependentObservable(function () {
return !(_this.OriginalStart() == _this.Start() &
_this.OriginalEnd() == _this.End() &
_this.OriginalIntervalTypeID() == _this.IntervalTypeID());
});
}
var viewModel;
$(function () {
var viewModel = {};
viewModel = new IntervalModel({ IntervalID: 1, Start: "09:00", End: "10:00", IntervalTypeID: 2 });
ko.applyBindings(viewModel);
});
</script>
Any help would be much appreciated... I need to use templates as i have lots of these intervals that need to be displayed.
Thanks!
There is an issue logged on github for this one here: https://github.com/SteveSanderson/knockout/issues/133
The issue centers around using numbers for the value of a select option. When a select element uses the value binding, it is updated with the actual value of the element, which is always a string. So, if your observable is 2, it gets set to "2" when the binding is set up. This change seems to cause an issue with any bindings that use that observable that were set up in the template prior to the select element.
So, until this is potentially fixed, you can make it work by passing IntervalTypeID as a string ("2"). An easy way to convert a number to string is to do yourvalue + ''.
Here it is working:
http://jsfiddle.net/rniemeyer/uDSFa/