This topic is locked
[SOLVED]

 Add Form - on selecting a date autofill another date

8/26/2011 7:55:01 AM
PHPRunner General questions
S
southside author

Hi;
I am using PHP Runner 5.3(Build 7474).
I have a table called candidate_data with a date field called registration_date, this uses the dropdown boxes with date picker date format.
On the add form when the user selects a registration_date I want the next field which is 10_week_date to be autofilled with the registration_date + 10 weeks (ie 70 days).
I ideally want the 10_week_date to also use the dropdown boxes with date picker date format.
Can you advise how this can be done without having to refresh or save the ADD FORM?
Stewart

C
cgphp 8/26/2011
S
southside author 8/26/2011

Cristian;
OK I have had a look but the code looks to be in part non UK language making it even more difficult to figure out.
I tried and example like this that Sergey posted but it did not do anything but maybe my code was wrong.
Have you any other examples?
Stewart

C
cgphp 8/26/2011

Please, post your code.

S
southside author 8/26/2011

Cristian;
I have dumped the code I tried and reset the javascript and cannot find Sergey's article but will have a look again just now and see if I can find it and post the code I was trying.
Stewart

S
southside author 8/26/2011

Cristain;
No luck just cannot find the article again and browser history is no good, can you help.
I just want a field 10_week_date filled in (+ 70 days) when registration_date is selected.
Stewart

S
southside author 8/26/2011

Cristian;
OK I found the thread http://www.asprunner.com/forums/topic/13678-how-to-calculate-values-on-the-fly/
But do not think it is correct for filling without save ie on change.
Jane's code was
######## START EXAMPLE

var ctrlPrice = Runner.getControl(pageid, 'Price');

var ctrlQuantity = Runner.getControl(pageid, 'Quantity');

var ctrlTotal = Runner.getControl(pageid, 'Total');
function func() {
ctrlTotal.setValue(parseFloat(ctrlPrice.getValue()) * parseFloat(ctrlQuantity.getValue()));

};
ctrlPrice.on('keyup', func);

ctrlQuantity.on('keyup', func);

######### END EXAMPLE
START MY ATTEMPT >>>>>
var ctrlregistration_date = Runner.getControl(pageid, 'registration_date');

var ctrl10_week_date = Runner.getControl(pageid, '10_week_date');
function func() {
ctrl10_week_date.setValue(parseFloat(ctrlregistration_date.getValue()) +70);

};
ctrlregistration_date.on('keyup', func);
END MY ATTEMPT

S
southside author 8/26/2011

My page view source code is this, maybe as the registration date is 3 select boxes my id's are wrong?
<tr>

<td nowrap="nowrap" class="es editshade_b" width="300">Registration Date</td>

<td width="245" class="es editshade_lb" style="padding-left:10px;"><span id="edit1_registration_date_0" style="white-space: nowrap;"><select id="dayvalue_registration_date_1" name="dayvalue_registration_date_1" ></select>&nbsp;<select id="monthvalue_registration_date_1" name="monthvalue_registration_date_1" ></select>&nbsp;<select id="yearvalue_registration_date_1" name="yearvalue_registration_date_1" ></select><input id="value_registration_date_1" type=hidden name="value_registration_date_1" value="">&nbsp;<a href="#" id="imgCal_value_registration_date_1"><img src="images/cal.gif" width=16 height=16 border=0 alt="Click Here to Pick up the date"></a><input id="tsvalue_registration_date_1" type=hidden name="tsvalue_registration_date_1" value="0-0-0"><input id="type_registration_date_1" type="hidden" name="type_registration_date_1" value="date13">&nbsp;<font color="red">*</font></span>&nbsp;</td>

<td class="editshade_cb">&nbsp;</td>

</tr>

C
cgphp 8/27/2011

Here is my solution:

var date_1 = $("input[id^='value_registration_date']");

var date_1_hidden = $("input[id^='tsvalue_registration_date']");

var date_2 = $("input[id^='value_10_week_date']");

var date_2_hidden = $("input[id^='tsvalue_10_week_date']");
var basic_value = date_1_hidden.val();
function add_weeks(my_date)

{

var number_of_days = 70;

var date_split = new Array();

var d1 = new Date();

var day = "";

var month = "";
date_split = my_date.split("/");

d1.setFullYear(date_split[2],date_split[1]-1,date_split[0]);

d1.setDate(d1.getDate() + number_of_days);



day = (d1.getDate() < 10 ? '0': '') + d1.getDate();

month = ((d1.getMonth()+1) < 10 ? '0' : '') + (d1.getMonth()+1);

return day + "/" + month + "/" + d1.getFullYear();

}
setInterval(function () {

if (date_1_hidden.val() != basic_value )

{

date_1_hidden.change();

basic_value = date_1_hidden.val();

date_2.val(add_weeks(date_1.val()));

date_2_hidden.val(date_2.val().replace(/\//g,"-"));

}

}, 400);
S
southside author 8/27/2011

Cristian;
Wow thanks that is way beyond my understanding.
I pasted the code into the candidate_data ADD PAGE - JavaScript OnLoad event.
I then did a full build went to the ADD PAGE and selected today as the registration date using the calendar which filled 27 - August - 2011 into the registration date but nothing was filled into the 10 week date it should autofill to today + 70 days.
What else do I need to do to make it work?
Many thanks for your help.
Stewart

C
cgphp 8/27/2011

I suppose you are using the 27/08/2011 as date format.

S
southside author 8/27/2011

Cristian;
Yes sorry I am using UK date format. DD/MM/YYYY English (United Kingdom) format in PHP Runner.
Stewart

C
cgphp 8/27/2011

What are the fields name ? Be careful with capitalization.

S
southside author 8/27/2011

Cristian;
The db table is candidate_data.
The db field names are registration_date & 10_week_date.
There are no caps on the table or field names only labels.
The labels for the fields are Registration Date & 10 Week Date.
Does this help.
Stewart

C
cgphp 8/27/2011

Does firebug throw any error or warning ?

C
cgphp 8/27/2011

I also suppose that the date field is an input text (not three select boxes) with datepicker.

S
southside author 8/27/2011

Cristian;
No I have tested in FF6.0 with all firebug panels enabled and when you select registration date you get no errors.
Stewart

C
cgphp 8/27/2011

Set the two date fields as "Simple edit box with datepicker".

S
southside author 8/27/2011

Cristian;
No I am using the 3 select boxes with date picker and picking today's date from the calendar date picker.

Stewart

C
cgphp 8/27/2011

To use my code you have to set the two date fields as "Simple edit box with datepicker".

S
southside author 8/27/2011

ok trying now

S
southside author 8/27/2011

Cristian;
Superb it works you are a star.
Many thanks for your help on this.
Stewart