Button click not triggering JQuery datepicker functionality

Currently, I am facing an issue with the jQuery datepicker functionality. It seems to work fine when clicking on a button in Mozilla Firefox, but unfortunately, it does not function properly in Google Chrome or Internet Explorer. Can someone please provide guidance on how to make the datepicker work seamlessly across all browsers? You can view the code on jsfiddle

HTML

<input type="button" id="selectdate" value="">
<textarea name="dates" id="dates" maxlength="160" placeholder="your message" rows="4" cols="50"></textarea>

JQUERY

$( "#selectdate" ).datepicker({ 
altField: $('#dates').val(), 
numberOfMonths:1, 
altFormat: "yy-mm-dd", 
minDate: -0, 
onSelect: function( selectedDate ) { 
$("#selectdate").val(''); 
$('#dates').val($('#dates').val()+','+selectedDate); 
} 
}); 

Answer №1

Check out the following solution:

Interactive Demo

JavaScript code snippet:

$("#selectdate").datepicker({
    altField: $('#dates').val(),
    numberOfMonths: 1,
    altFormat: "yy-mm-dd",
    minDate: -0,
    buttonImage: 'http://placehold.it/32',
    showOn: "both",
    onSelect: function (selectedDate) {
        $("#selectdate").val('');
        
        var attr = $("#dates").attr("selectedDate");
        if (typeof (attr) !== 'undefined' && attr !== '') {
            if ($('#dates').val() !== '') {
                var tmpVal = $('#dates').val().substring(0,$('#dates').val().indexOf(attr));
               console.log(tmpVal); 
              $('#dates').val(tmpVal + selectedDate);
              $('#dates').attr("selectedDate", selectedDate);
            } else {
                $('#dates').val(selectedDate);
            }
        } else {
            $('#dates').attr("selectedDate", selectedDate);
            $('#dates').val($('#dates').val() + selectedDate);
        }
    }
});

Answer №2

Although I couldn't replicate the issue, it seems like the solution lies in utilizing the showOn and buttonImage options instead of relying on a button to display the datepicker.

For example:

<input type="text" id="selectdate" value="" style="display: none">

Followed by:

$("#selectdate").datepicker({
    altField: $('#dates').val(),
    numberOfMonths: 1,
    altFormat: "yy-mm-dd",
    minDate: -0,
    buttonImage:'http://placehold.it/32',
    showOn: "both",
    onSelect: function (selectedDate) {
        $("#selectdate").val('');

        $('#dates').val($('#dates').val() + ',' + selectedDate);
    }
});

Check out the demo here: Fiddle

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Step-by-step guide for setting up chartjs on Laravel 6 using npm

Can anyone guide me on how to properly install and integrate [email protected] in my laravel application? Currently, I am using cdn links, but I want to avoid that in the future. List of cdn links being used: <script src="https://cdnjs.c ...

The Bootstrap modals seem to be invisible within the Rails application

Currently, I am integrating jquery into the devise views of a sample rails application. My intention is to test it on a sample app before implementing it in a production code. The controller and view for welcome are already set up. The routes.rb file loo ...

- Customizing the width of each dropdown level in a unique way

Working on a customized menu design that you can view live at: Focusing on the third level menu, I encountered an issue where all menus have the same width due to sharing the dropdown-menu class. While I understand the root cause of the problem, I am unsu ...

What is the process for creating a local repository for Node.js npm?

When it comes to the building process in node js, there are a few goals that need to be called: Begin by calling npm install, which creates a folder called node_modules and places all dependencies from package.json into it. [for UI development] Execute a ...

Is it possible to optimize and condense CSS code for a more streamlined and efficient style?

I've defined the following styles in an external CSS file. .callButton { width: 100px; height: 25px; float: right; /* other styles here */ background-img: url('images/callButton.png'); } .otherButton { width: 100px; height: 2 ...

Unable to adjust the dimensions of the image

I recently added two images to my website successfully, but I am facing an issue when attempting to modify their dimensions and shape using CSS. Despite adjusting the height, width, border-radius, etc., the images remain unchanged. Can anyone provide insig ...

Every time I make a change to the code, Laravel's css/app.css file mysteriously vanishes from the mix-manifest.json

Whenever I make a change in my code, the line css/app.css in mix-manifest.json disappears. The only solution is to execute npm run watch or npm run dev, but the problem reoccurs each time I modify the code. Here is how my mix-manifest.json looks when eve ...

updating the datepicker input maxDate property to the current date

I am facing a challenge with setting the input date using datepicker. I want to require the user to choose a date less than the current date. Below is the code snippet: <div class="tab-pane fade active in" id="evenement"> < ...

How can we eliminate duplicate objects in a JavaScript array by comparing their object keys?

I am trying to remove duplicate objects from an Array. For example, the object 'bison' appears twice. var beasts = [ {'ant':false}, {'bison':true}, {'camel':true}, {'duck':false}, {'bison':false} ...

Seeking assistance with setting up BxSlider installation

I'm struggling with adding bxslider to my HTML template. No matter what I try, the slider doesn't work as expected. When I preview my website, all three images are displayed together in a single column. Can someone please guide me on how to fix t ...

Coloring a table in vue.js based on performance rankings

I'm facing an issue with sorting my data performance in vue js. Here is the script I have created so far: <template> <div> <div class="row"> <h2> Campaign Performance </h2> <table class=&q ...

The Vimeo player JavaScript API is experiencing issues on iOS devices

I am facing an issue where the API for playing a video only works on iOS after the play button is clicked in the player. However, it works fine on desktop and Chrome for Android. http://codepen.io/bdougherty/pen/JgDfm $(function() { var iframe = $(&a ...

Using a jQuery gallery can cause links to become unresponsive and unclickable

While creating a responsive webpage with the Zurb Foundation framework, I encountered an issue when trying to incorporate nanoGallery which also uses jQuery. After adding the gallery scripts, the top menu generated by the Foundation script became unclickab ...

Determining the width of a window using JavaScript

My website is experiencing some mysterious issues with $(window).width(). When I open my site in the Chrome Device Toolbar with a window size of 320xXXX, then run $(window).width() in Google Chrome's JavaScript console, it returns 980. As a result, n ...

Struggling to increment the badge counter in a React Typescript project

I'm a bit unsure about where to apply the count in my Badge Component. The displayValue should include the count, but I'm struggling with how to implement it. UPDATE: The counter is now in place, but when I decrease the count and it reaches 0, t ...

"Implementing drag and drop functionality in Vue.js without the need for a

Exploring html 5 drag and drop functionality using vue js has been a challenging experience for me. After following the w3schools tutorial on drag and drop, I managed to get it working in a basic html file but faced difficulties when implementing it in my ...

Position a flash element adjacent to an input field

I'm struggling to properly align two elements together. Below is the HTML code: <input class='pretty-border' id='shareinput' value='afdsdasfdasfadsff' /> <span> <object classid="clsid:d27cdb6e-ae6-11c ...

What is the method for developing a Typescript-connected High-Order React Component with Redux?

I am looking to develop a React Higher-Order Component that can safeguard routes within my application from unauthorized users without an access token. I aim to use this HOC to wrap a Component like so in the parent component: <Route exact path ...

"Bootstrap is not aligning div md-6 as expected, instead it is sending it

Within my simple layout, I have 4 columns (col-lg3 col-md/sm-6 and col-xs-12). The display is straightforward, like this: https://i.sstatic.net/OyhNkm.png Everything functions perfectly when each column has a width of 3. However, when they adjust to md o ...

I'm curious if there is a method in Vue.js that allows for creating a separator while utilizing v-for, much like the way `Array.join()` or FreeMarker's `<#sep>` functions operate

My goal is to create a list of <span> elements separated by commas using vue.js and v-for. Is there an easy way to achieve this in vue.js? In JavaScript, I would typically use users.join(", "). In FreeMarker templates, you can do some very interes ...