jquery date picker ristrict date range

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

jquery date picker ristrict date range

Post by jonnyfortis »

I have a date picker that currently gives a full date range and works fine. the date picker is for people to select when they move into a certain property. that is held in a PHP DB. i want to be able to be able to set the date picker to only show the dates when the property is available to move into. Ideally the available move in date is set up in the backed of the system so therefore stored in the DB

i have all the code is required.

i am using PHPmyadmin SQL
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: jquery date picker ristrict date range

Post by pickle »

Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: jquery date picker ristrict date range

Post by jonnyfortis »

i have seen this but does this show you how to administer via a php back end
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: jquery date picker ristrict date range

Post by pickle »

Just echo the date from PHP into a javascript variable, then use that variable in your javascript.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: jquery date picker ristrict date range

Post by jonnyfortis »

pickle wrote:Just echo the date from PHP into a javascript variable, then use that variable in your javascript.

ok can you give me a clue howi do this? it would be of great help
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: jquery date picker ristrict date range

Post by pickle »

Code: Select all

<script type = "javascript">
var minDate = '<?php echo $the_date_from_the_database; ?>';

$("selector").datepicker({minDate: minDate});
</script>
You may need to do some formatting to convert the date in the database to a format usable by datepicker, but that's the general way to do it
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: jquery date picker ristrict date range

Post by jonnyfortis »

pickle wrote:

Code: Select all

<script type = "javascript">
var minDate = '<?php echo $the_date_from_the_database; ?>';

$("selector").datepicker({minDate: minDate});
</script>
You may need to do some formatting to convert the date in the database to a format usable by datepicker, but that's the general way to do it

ok thanks

this is the script i have at the moment, basically what i have is field one is the datpicker, i then have 2 radio button one for 43 weeks and the other for 52 weeks. what ever they select it will give the datepicker date plus the 34 / 52 weeks

<script type="text/javascript">
$(function(){

$('.date-pick').datepicker({ dateFormat: 'dd/mm/yy' });

$("input[name='weeks']").change(function() {

var start = $('input[name="StartDate"]').val();
var weeks = $('input:radio[name="weeks"]:checked').val();

var date = new Date(start);
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();

myInteger = parseInt(weeks);

var edate= new Date(y, m, d+myInteger);

edate = edate.format("dd/mm/yyyy");

$('input[name="EndDate"]').val(edate);

});


});
</script>


<input type="text" value="" name="StartDate" id="StartDate" class="date-pick" size="30" />

<td width="180" class="table-text"><input type="radio" value="364" name="weeks" validate="required:true" />
52 weeks &nbsp;
<input type="radio" value="301" name="weeks" />
43 weeks</td>

<input type="text" value="" name="EndDate" id="EndDate" size="30" />


so i need to add a column in the db that will show the min date? how do i add that code to my existing code?


thanks so much for you help
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: jquery date picker ristrict date range

Post by pickle »

All your code is javascript (which you should wrap in

Code: Select all

[/script] tags).  To add a column to your DB, you'll need to do some work in SQL, and some PHP code.

Generally questions that get answered are of the format, "I've tried X, here is my code, the problem I'm having is Y".  It's difficult for me at least, to just do the work for you.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: jquery date picker ristrict date range

Post by jonnyfortis »

pickle wrote:All your code is javascript (which you should wrap in

Code: Select all

[/script] tags).  To add a column to your DB, you'll need to do some work in SQL, and some PHP code.

Generally questions that get answered are of the format, "I've tried X, here is my code, the problem I'm having is Y".  It's difficult for me at least, to just do the work for you.[/quote]


ok all the code is already wrapped in the tags as you suggested. i am trying to get it working myself.

thanks for your time
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: jquery date picker ristrict date range

Post by jonnyfortis »

jonnyfortis wrote:
pickle wrote:All your code is javascript (which you should wrap in

Code: Select all

[/script] tags).  To add a column to your DB, you'll need to do some work in SQL, and some PHP code.

Generally questions that get answered are of the format, "I've tried X, here is my code, the problem I'm having is Y".  It's difficult for me at least, to just do the work for you.[/quote]


ok all the code is already wrapped in the tags as you suggested. i am trying to get it working myself.

thanks for your time[/quote]


I have looked at what i need to do but am totally stuck. i would say i have tried x to get to y but dont really know where to start
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: jquery date picker ristrict date range

Post by pickle »

Start at getting the javascript to do what you want. Then update your database to have a new column. Finally, update your PHP code to take what is given from Javascript, and properly put it in the database.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: jquery date picker ristrict date range

Post by jonnyfortis »

pickle wrote:Start at getting the javascript to do what you want. Then update your database to have a new column. Finally, update your PHP code to take what is given from Javascript, and properly put it in the database.

i understand the concept just having trouble linking it in.
Post Reply