Hello,
with Jason's Date Input Calendar, http://www.dynamicdrive.com/dynamici...oncalendar.htm, how can I retrieve the value of the selected date in a variable?
Thank you.
Hello,
with Jason's Date Input Calendar, http://www.dynamicdrive.com/dynamici...oncalendar.htm, how can I retrieve the value of the selected date in a variable?
Thank you.
Get a reference to the hidden field that contains the date and get its value. There are many ways to do that. They all would use the name that you created the calendar with. So, say you made a calendar like so:
The most direct method, assuming there are no other elements or calendars on the page with the 'orderdate' name, would be:Code:<script>DateInput('orderdate', true, 'DD-MON-YYYY')</script>
Generally you will not need this though because, if the 'orderdate' calendar is in a form, and if that form is submitted, then the POST or GET value of ['orderdate'] will be the currently selected date.Code:var myvar = document.getElementsByName('orderdate')[0].value;
But, of course if you do need it in javascript you need to do that each time you want it, as it might have changed. You could set an interval.
But, if I do (in Chrome's developer tools):
I get this information:Code:console.log(orderdate_Object.picked)
So, in real time you could skip the myvar part, and wherever you wanted this value you could represent it as:Code:storedMonthObject { date: Fri Aug 02 2013 00:00:00 GMT-0400 (Eastern Daylight Time) day: 2 dayCount: 31 dayPad: "02" firstDay: 4 formatted: "02-AUG-2013" fullName: "August 2013" monthIndex: 7 monthName: "August" monthPad: "08" monthShort: "AUG" yearPad: "2013" yearValue: 2013 }
or:Code:orderdate_Object.picked.formatted
or whatever exactly you want to retrieve from the picked object.Code:orderdate_Object.picked.day + ' ' + orderdate_Object.picked.fullname
Why do you want this, what are you planning on doing with it?
Last edited by jscheuer1; 08-02-2013 at 02:42 PM. Reason: fix typo in code add orderdate_Object method
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
siecool (08-02-2013)
Pretty much like any other form, I would say - you would post the form and retrieve the value from the named field.
From the DD demo page;
Code:<script>DateInput(DateName, Required*, DateFormat*, DefaultDate*)</script>So this is the name you retrieve when the form is posted;DateName: STRING - required. Name of the hidden form element to store the selected, formatted date You do NOT need to create this field manually in your form.
If you need more help, please post a link to your page. Your form processing script may also be required.PHP Code:$datename = $_POST['DateName']; // change to whatever name you've used in the JavaScript ('DateName' is just used in the demo)
echo $datename;
// would output something like " 02-Aug-2013 " if the DateFormat parameter is set as " DD-MON-YYYY "
EDIT: John and I are posting at the same time (I am obviously much slower on the keyboard) but I think our posts collectively provide a nicely rounded explanation and other available options.
Last edited by Beverleyh; 08-02-2013 at 01:53 PM. Reason: Hello John!
Focus on Function Web Design
Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps
siecool (08-02-2013)
Thank you. But How to put two different calendars on the same page?
Just use a different DateName in each JavaScript call.
Focus on Function Web Design
Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps
siecool (08-02-2013)
create a new global variable
where orderdate if parameter 0 of the call DateInput('orderdate', true, 'DD-MON-YYYY') + 'V'Code:var orderdateV='not set'
the html
add the line in redCode:<form> <input type="button" name="" value="Test" onmouseup="alert(orderdateV);" /> <script>DateInput('orderdate', true, 'DD-MON-YYYY')</script> <input type="button" onClick="alert(this.form.orderdate.value)" value="Show date value passed"> </form>
Code:// Sets the form elements after a day has been picked from the calendar function PickDisplayDay(ClickedDay) { this.show(); var MonthList = this.getMonthList(); var DayList = this.getDayList(); var YearField = this.getYearField(); FixDayList(DayList, GetDayCount(this.displayed.yearValue, this.displayed.monthIndex)); // Select the month and day in the lists for (var i=0;i<MonthList.length;i++) { if (MonthList.options[i].value == this.displayed.monthIndex){ MonthList.options[i].selected = true; } } for (var j=1;j<=DayList.length;j++) { if (j == ClickedDay) DayList.options[j-1].selected = true; } this.setPicked(this.displayed.yearValue, this.displayed.monthIndex, ClickedDay); // Change the year, if necessary YearField.value = this.picked.yearPad; YearField.defaultValue = YearField.value; window[this.hiddenFieldName+'V']=[MonthList.value,ClickedDay,this.picked.yearPad]; }
Vic
God Loves You and will never love you less.
http://www.vicsjavascripts.org/Home.htm
If my post has been useful please donate to http://www.operationsmile.org.uk/
Bookmarks