CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> General/Other

 Customise date picker

Print topic Send  topic

Author Message
karen

Posts: 99
Posted: 01/12/2009, 7:09 PM

Hi all,

I hope someone will be able to help me with this. I have a date field that has an associated date picker. I would like to use javascript to validate this field such that only Sundays are picked. I am open to how it is done, e.g., can customise the date picker to only allow Sundays to be clicked or the way I have attempted is to validate the date after it is returned in the onchange event of the date. This is roughly how my script goes but nothing seems to happen...

var dayofweek = document.getElementById("input_date").getDay();
var numdate = Number(document.getElementById("input_date").value();
var enddate= dayofweek + numdate;
document.getElementById("input_date").value = enddate;
if (dayweek)
alert("The date selected is not a Sunday and has been modified to " + enddate);

I would really appreciate any tips at all and am quite open to different ways of achieving this. My last resort would be to use PHP server validation.

Pls help! Thanks in advance.

Cheers,
Karen
View profile  Send private message
jjrjr1


Posts: 942
Posted: 01/18/2009, 7:50 AM

Hi

The best I can see here at first glance, your test for dayweek will always fail. Where is dayweek set?

Also maybe {} around the alert or put the alert on the same line as the if(dayweek).

I do not think dayofweek has the value you expect for the getDay() method to work. What is that function returning? Try a document.write(dayofweek) and be sure it is a integer representing that actually reflects the day of week.

The getDay() method expects a timestamp like so.

var date_time= new Date();

dayofweek = date_time.getDay();

I think in your case date picker has already changed the date to mm/dd/yy so I doubt getDay() can work.

Also where you get numbdate, might also be not giving you the value you expect.

So to get the correct day of week try

var CCSDate=getElementById("input_date").value();
var CCSTestDate = CCSDate.split("/"); //or what ever your date separator is

now you have an array you can use in the Date() function.

Var DatePickerSelectedDate = new Date(CCSTestDate[0],CCSTestDate[1]-1,CCSTestDate[2],0,0,0);

incidentally the date value used in this example above assumes the date in YYYY/MM/DD is being returned by DatePicker.

If your ccs project returns the date in a different format you must ensure you manipulate the strings after the split function so index [0] is the 4 digit year [1] is the 2 digit month and [2] is the 2 digit day

Then you can do:

dayofweek = DatePickerSelectedDate.getDay();
day of week should be 0 = 6 sun thru sat.

I have not tested this but it might work for you.

Let me know



_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
karen

Posts: 99
Posted: 01/18/2009, 3:28 PM

Hi John,

First of all, thanks so much for your very detailed reply. It makes much sense and I had also figured out that the getDay() method wasn't working due to the input field not being in the right format.....after spending hours :P And since I am not very good at javascript, I had actually resorted to using server-side scripting (PHP) to check and got that to work. However, that's not as user-friendly as what I had intended to do. So now that I've got some very good tips here, I'll test it out and report back how I go.

Thanks for your time again!

Cheers,
Karen
View profile  Send private message
jjrjr1


Posts: 942
Posted: 01/18/2009, 4:05 PM

Glad to help.

Let me know if it works or if we need to try something else.

Have fun.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
karen

Posts: 99
Posted: 01/27/2009, 6:21 PM

Hi John,

I'll have to laugh at myself and you can have a laugh too! After going thru and changing the code and then finding nothing happens when testing it, I then realised that there was another problem I had with the onchange event not firing when using the date picker!

I must try something else (other than the onchange event). In the meantime, if you have some ideas, I would really appreciate that.

Rgds,
Karen
View profile  Send private message
jjrjr1


Posts: 942
Posted: 01/27/2009, 7:25 PM

Hi Karen

You need to put the onchange event on the control which gets the results from datepicker.

I have used this to validate dates on the client side and will work.

So the custom code created for this requirement needs to be attached to the onchange event for whatever control datpicker is filling.

Let me know if that works or I am missing something

Have fun

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
jjrjr1


Posts: 942
Posted: 01/28/2009, 9:59 AM

Hi

Another thought.

If datepicker does not fire the onchange event for the control, try doing this validation in the page level on unload event.

Maybe that will help.


_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.