Title: Drop Down Select
Last modified: January 29, 2023

---

# Drop Down Select

 *  Resolved [gatestar](https://wordpress.org/support/users/gatestar/)
 * (@gatestar)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/drop-down-select-2/)
 * Hi I have a timesheet form that has fields with dropdowns for times so like 08:
   00am 80:30am and so on. This is saved in a custom table, can then get the plugin
   to read this, but it pulls only the data into the field and overwrites the list,
   can I get it to select the appropriate value that has been saved? So if the person
   selected 08:00am that would be selected but the user can change this and select
   from the other options.
 * Thanks

Viewing 1 replies (of 1 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/drop-down-select-2/#post-16419654)
 * Hello [@gatestar](https://wordpress.org/support/users/gatestar/)
 * Thank you very much for using our plugin. In this case, you don’t want to fill
   the field with the values stored in the database table. You want to select the
   value from the existing dropdown field. A possible alternative is the use of 
   callbacks.
 * I’ll try to describe the process with an example.
 * Assuming I have the dropdown field posts with some posts ids as their choices:
 *     ```wp-block-code
       [select posts "--SELECT--" "22" "23"]
       ```
   
 * Now, I want to read the list of published posts from the database and select 
   the first choice that matches any of the posts read from the database. I insert
   the record-set tag to read the posts ids from the database and include the callback
   argument:
 *     ```wp-block-code
       [cf7-recordset id="posts-data" type="post" attributes="ID" condition="post_type='post' AND post_status='publish'" callback="select_option"]
       ```
   
 * Finally, I implement the callback function in the form content:
 *     ```wp-block-code
       <script>
       function select_option(records) {
         var e;
         for(var i in records){
           e = jQuery('[name="posts"] option[value="'+records[i]['ID']+'"]');
           if( e.length ){ e.prop('selected', true); return;}
         }
       }
       </script>
       ```
   
 * The complete form structure would be:
 *     ```wp-block-code
       <label> Posts Ids
           [select posts "--SELECT--" "22" "23"] </label>
   
       [cf7-recordset id="posts-data" type="post" attributes="ID" condition="post_type='post' AND post_status='publish'" callback="select_option"]
   
       <script>
       function select_option(records) {
         var e;
         for(var i in records){
           e = jQuery('[name="posts"] option[value="'+records[i]['ID']+'"]');
           if( e.length ){ e.prop('selected', true); return;}
         }
       }
       </script>
       ```
   
 * Now, you only should modify your record-set tag to include the callback argument
   and implement the callback function adjusted to your project needs.
 * Best regards.

Viewing 1 replies (of 1 total)

The topic ‘Drop Down Select’ is closed to new replies.

 * ![](https://ps.w.org/cf7-data-source/assets/icon-256x256.gif?rev=2508392)
 * [Data Source for Contact Form 7](https://wordpress.org/plugins/cf7-data-source/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cf7-data-source/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cf7-data-source/)
 * [Active Topics](https://wordpress.org/support/plugin/cf7-data-source/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cf7-data-source/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cf7-data-source/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [codepeople](https://wordpress.org/support/users/codepeople/)
 * Last activity: [3 years, 4 months ago](https://wordpress.org/support/topic/drop-down-select-2/#post-16419654)
 * Status: resolved