jQuery how to event fire for todays date only? - javascript

I tried to fire event for today's date only.
For a reason, I can't use Date picker onselect / onClose method.
Now I want to do it directly when just select todays date from datepicker.
I'm using class for fire event. But now Working.
jQuery("td.ui-datepicker-today a").click(function(){
//event trigger.
});
Can anyone give me any suggestion ?

You may try following
jQuery("body").on("click","td.ui-datepicker-today a",function(){
//event trigger.
});

Jquery click event will not work with the elements that are dynamically added to dom.
You need to use on or bind methods in jquery to achieve this.

Related

Datepicker does not show at first click

I've just created a simple textbox where inside I binded the .click event to show the Datepicker, anyway, seems that at first click the Datepicker can't show, but if I click outside the control and then click again over the textbox I can see the Datepicker, I wonder why happen this?
Check out my code here:
<input type="text" id="calendar" placeholder="calendar">
$(function()
{
$('#calendar').click(function()
{
$(this).datepicker();
});
});
FIDDLE.
You are initializing Date picker on your text box click. You have to initialize on document ready method if you want to Open date picker immediate after page load
Change your initializing code to
$(function()
{
$('#calendar').datepicker();
});
For your reference fiddler updated
You don't have to use the click event to start the date picker.
All you have to do is remove the click event and it will work!
The date picker is already attached to your input box and will handle the events by itself.
Calling datepicker() does not invoke the calendar display. What datepicker() did was to attach a 'show calendar' event on input-focus. That's the reason why you see the calendar only when you put the focus back on the input field (not on every click of #calendar element).
If you want to trigger the display of calendar due to some other event (like button click), you can call $('#calendar').datepicker('show').

onchange event value changed programmatically

It's possible (using jQuery or native JS) catch a change event for an input whose value is changed programmatically?? I'm not able to fire the event when the value changes.
Thx for your time.
Sure:
$("input").change(function() {
// listening for changes
});
// triger change event manually
$("input").change();
Most of the jQuery event handlers are also triggers.
For example, you can trigger the change() event as follows:
jQueryElement.change();
Or, you can use the jQuery trigger() function for any event:
jQueryElement.trigger("change");
With regular JavaScript (because jQuery isn't always necessary), use dispatchEvent():
jsElement.dispatchEvent("change");
Links to documentation pages are included.

Modify jQueryUI datepicker buttons

The jQueryUI datepicker can be setup with a Today and Done button. See http://jqueryui.com/datepicker/#buttonbar.
How can I trigger some event (i.e. alert('close');) whenever the Done button is clicked, and then continue with the buttons default functionality (i.e. closing the calender).
Note that I do not wish to use the onClose() method as this is triggered when the calender is closed through any means (i.e. clicking off the calender), and not necessarily when the Done button is clicked.
PS. I don't think it is relevant, but I am using the datepicker in connection with http://trentrichardson.com/examples/timepicker/
You can create a separate handler by using event delegation.
$(document).on('click', 'button.ui-datepicker-close', function(){
alert('close')
});
I bound the event handler to the Done button as it's not entirely clear what behavior you want although I think this is what you are asking
DEMO

jQuery Simulate onClick

I am trying to simulate an onclick event on a drop down.
I have an IE object that is going to a page and I need to change a dropdown which has an onchange event:
$('select[name="blah"]').val(3).trigger('change');
$('select[name="blah"]').change(function(){
alert('changed');
});
When I try this, I would expect the alert to fire as it's technically an onchange.
http://jsfiddle.net/3y5hmyf0/
Is there a way to acomplish this?
More Details
My tool is controlling another IE page through an object. It navigates to the page and finds the select drop down on the page. From there, if you did it manually it has an onchange event when making a selection.
I am trying to get jQuery to simulate as if it was being clicked by a person to it triggers that on change event.
I have tried .trigger and .change and couldnt get either of them to work.
The only reason your code does not work is the order you are executing it. You need to connect the handler before triggering it:
JSFiddle: http://jsfiddle.net/3y5hmyf0/1/
// Wire up event handler
$('select[name="blah"]').change(function(){
alert('changed');
});
// Now generate the event
$('select[name="blah"]').val(3).trigger('change');
Note: Your manual change trigger is still required as a change event must normally be triggered by user interaction. Setting the value is not enough.
$('select[name="blah"]').change(function(){
NotifyChanged();
});
function NotifyChanged() {
alert('changed');
}
If you want to test the logic in the changed function, just call it.

Strange function with datepicker behaviour in firefox and Chrome

I want to use severall datepickers one one page, so i putt the datepicker in a function. The function is triggered on a onfocus event. This works perfect in IE, also in firefox/chrome, but in Firefox i have to click on the input field, lose focus and click again before i get a datepicker....
See the example: http://www.huurhulp.nl/prijzen.php
First click on the second bullet "wij zijn bepaalde periodes gesloten" To unhide the input fields.
Any idea how to get it working in one click in firefox?
Instead of creating your datepickers in onfocus events create them in your $(document).ready block.
The datepicker plugin internally uses the focus event to show the datepicker widget so using it to create the widget is a bad idea.
Looking at your code doing something like this should work:
$(function() {
$('.datums').datepicker({
//List your options here.
});
});

Categories

Resources