Field value based on selection in dropdown

Theon 04 Feb, 2015
Is it possible to automaticly have a field value set, based on the selection that is made in a dynamic- dropdown?
In my 'DB Read' i also 'read' that value.

What i mean is something like a selection of e.g. category, which shows a list of members in the second dropdown and then automaticly show their phone number in a field next to the dropdown once selected.
Any idea how to do so??

Note: The question is about the phone number. I've got a working dynamic-double-dropdown.
GreyHead 06 Feb, 2015
Hi Theon,

I think that the simplest way to do this would be a second Ajax request back to a form event when a member is selected to get their phone number.

Bob
Theon 06 Feb, 2015
Hello Bob,

Thanks for your reaction.
I did as you suggested and got it to work.
Thanks again

Theon
Mileto 22 Feb, 2015
Hi Theon an Bob

Can you post example of code to use in ajax event to set a field after dropdown select?

I want to set more field after select an id from a dropdown, whit this id i must load data from db and set the fields.

Ty
Angelo
Theon 25 Feb, 2015
Hello Angelo,
Sorry for my late reply, i've been kind of busy lately.
Do you mean something like this?

In Event "Load_number", i created a "DBRead" with the following php in the conditions box:
<?php
return array( 'id' => $form->data['id'] );
?>

The first 'id' is the name of my database-row,
The second is the 'form-name'.

This should select data from database.

Then in 'on found' a custom code:
<?php
$options = array();
if ( !$form->data['Data'] || count($form->data['Data']) < 1 ) {
// no result was found
$options[] = 'nothing found';
}
else {

foreach ( $form->data['Data'] as $d )
{
$options[$d['number']] = $d['number'];
}
}
echo json_encode($options);
?>

Both fields 'number' should excist in your form and database.
This loads the found data from your database to the field 'number' in your form.
You have to enable 'Dynamic Data' for your 'number' field.

PS. I have created a dropdown field for this to, to get it to work.
This dropdown can only hold one 'answer' in my case.
but it was what i needed.

Hope it helps you,

Greetings Theon
This topic is locked and no more replies can be posted.