Solved

How to append the selected date to a hidden input using jquery ui datepicker?

Posted on 2014-10-22
4
461 Views
Last Modified: 2014-10-23
Experts,

When using the jquery ui datepicker, I'd like to append the date the user selects to a hidden input field so that I can pass the value upon form submission.  Any assistance you could provide would be much appreciated.

Here's my fiddle which shows my current working code:

http://jsfiddle.net/bdbarrera/tf1vrf0v/

Just not sure how to modify the javascript to grab the date once it is selected?

Cheers!
0
Comment
Question by:evibesmusic
4 Comments
 
LVL 35

Assisted Solution

by:Robert Schutt
Robert Schutt earned 300 total points
ID: 40398790
use onSelect to add a callback function:
            //CREATE CALENDAR OBJECT
            $("#calendar").datepicker({autoSize:true, onSelect:function(selectedDate, objDatePicker){
                $('#stoppage_date').val($('#stoppage_date').val() + ',' + selectedDate);
            }});

Open in new window

updated fiddle: http://jsfiddle.net/robert_schutt/tf1vrf0v/6/
(note that I used a TEMP visible input to more easily check that it works)
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 200 total points
ID: 40399133
also hide your calendar container with CSS else we need to click twice on the button the first time :
http://jsfiddle.net/tf1vrf0v/7/
0
 
LVL 11

Expert Comment

by:Murfur
ID: 40399146
Daft question for you: why have a hidden field and not just capture the date selected from the date field on form submission?
0
 

Author Closing Comment

by:evibesmusic
ID: 40399646
@All:

Thank you very much for the assistance. Much appreciated.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question