Set default value depending on user selection

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
zimra
User
Posts: 37

Set default value depending on user selection

Post by zimra »

Hello,

Is there a possibility in PHPMaker to calculate and set default values depending on what the user just choose or select .

An example, i have 2 "select" fields and 2 Date fields:
Field 1: owner ---Martin

Field 2: Car Model ---VW Touran

Field 3: Proposed Technical Inspektion (This inspection has to be done all two years and it is calculated dependent to the last technical inspection date,
the owner and the car Model.
This date is "dynamically" calculate and set as default and will be different from owner to owner and from car model to car model) ---12.02.2015

Field 4: Technical Inspection (When the proposed date is not possible) ---The user can choose 10.02.2015

Thank you!


danielc
User
Posts: 1601

Post by danielc »

You need to write your function to calculate and attach change event (see http://api.jquery.com/change/) to the field that you want to trigger the calculate.

You can use Startup Script (see Server Events and Client Scripts in the help file) to attach your onchange event.

zimra wrote:
it is calculated dependent to the last technical inspection

You need to make the last technical inspection date available for the onchange event to calculate. If the data is not available in the table, you'll need to write code to get it by Ajax, for example.


zimra
User
Posts: 37

Post by zimra »

Hallo Daniel,
Thank you for the hints.

i have some difficulties, i've defined this script:

<script type="text/javascript">

// Write your table-specific startup script here
// document.write("page loaded");
$(".x_FK_CarModel").change(function(){
alert("The text has been changed.");
if($(this).val() == "VW Touran") { -- I have to give the value of this field (VW Touran is wrong), but it is complicated, below is the code for this field
$("x_PROPOSED_DATE").append("<option value='date'>22/02/2014</option>"); // The proposed date is defined in PHPMaker as TEXT in the Add Page, i have to extend this part to calculate the date.
}
});
</script>

<select id="x_FK_CarModel" name="x_FK_CarModel" <?php echo $model->FK_CarModel->EditAttributes() ?>>
<?php
if (is_array($model->FK_CarModel->EditValue)) {
$arwrk = $model->FK_CarModel->EditValue;
$rowswrk = count($arwrk);
$emptywrk = TRUE;
for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
$selwrk = (strval($model->FK_CarModel->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>> -- I think this the value to retrieve
<?php echo $arwrk[$rowcntwrk][1] ?>

							<?php if ($arwrk[$rowcntwrk][2] <> "") { ?>
								<?php echo ew_ValueSeparator(1,$model->FK_CarModel) ?><?php echo $arwrk[$rowcntwrk][2] ?>
							<?php } ?>
				
							<?php if ($arwrk[$rowcntwrk][3] <> "") { ?>
								<?php echo ew_ValueSeparator(2,$model->FK_CarModel) ?><?php echo $arwrk[$rowcntwrk][3] ?>
							<?php } ?>
						</option>
			<?php
					}
				}
			?>
			</select>

Can you give help me please or give me an example how to get it with jquery.

Thank you


danielc
User
Posts: 1601

Post by danielc »

zimra wrote:
$(".x_FK_CarModel").change(function(){
$("x_PROPOSED_DATE")

Check if you use the correct selector to choose (in your case, you select class with name x_FK_CarModel and just name for x_PROPOSED_DATE). If you use id, you need to use "#". See this, http://api.jquery.com/category/selectors/


Post Reply