Select dropdown properties and DB update

After several attempts, I can not figure out how the select dropdown property works when you want to save the selected item into a table. Let’s say that I have a very simple table named Companies, with a field varchar named Province. Then I have another table called Province that lists all the Province names.

What I do is that I set up a form with a select element and I link it the a server connection that does the query in the Province table. In this way I have the select pre-populated with all the province.

The problem is when I try to save the selected Province in the varchar field of the Company table.

There is no way to update the province name. In the same form there is also an input field to update the company name and it works perfectly. The problem comes up only with the select form.

Any help is appreciated. I have read any possible threat and watched so many video. I understand that most of you are developers and probably this is a question for very beginners but I could not find any tutorials specific on this topic. Many thanks

Hello,
On your first screenshot, in the “Selected Value” field you should bind the value returned by the database query for the current record, so if in database the “province3” is stored, then it will show “province3” selected in the dropdown.

Then your question about “Value Field” - you should first understand how a select/dropdown menu works. See the code created for a dropdown:

<select id="myselect" name="myselect">
  <option value="1">Province 1</option>
  <option value="2">Province 2</option>
  <option value="3">Province 3</option>
</select>

value is what you pass to your database on form submit, the Text is just what the users see on the page. The value usually holds IDs of the records you show in the Text.

In the update record you pass the select menu as any other input on the page … if your select menu name is myselect then your post variable will be {{$_POST.myselect}}

Got it ! Thank you @Teodor

Can I ask you one more question ? Is it possibile put a placeholder in the select dropdown or leave the first element blank ? Thanks

<select id="myselect" name="myselect">
  <option value="">Please Choose ...</option>
  <option value="1">Province 1</option>
  <option value="2">Province 2</option>
  <option value="3">Province 3</option>
</select>

Enter your static placeholder option here:

Screenshot_30

Done :ok_hand:

1 Like

HI Teodor,

Is there a way to just use a list rather then populating this options table. I think I remember seeing somewhere that I can just use a list, but don’t remember the syntax. Thanks,

@wahlrab what do you mean to use a list?
Are you referring to dynamic data or something else?

Apologies, I mean a static dropdown box. Is it possible to place these values in list form in the options properties section instead of manually entering into the table. ie. ‘Op1’,‘Op2’,‘Op3’ etc. I have a few static dropdown to make that have a large amount of static options.

Not sure what do you mean by “list” … if you add them manually you should either add them using the UI (table) or add them in the code.

ah perfect, I can probably locate them in the code and add quicker from there. I just thought I remembered that I was able to add them in this format to the options properties section ‘Option1’, ‘Option2’ etc.