Combo default value from php connector

I have a combo in my form the gets its values from a MySQL table.
json:

{ type: "combo", name: "hazard", label: "Hazard: ", inputWidth: 250, tooltip: "Select the appropriate hazard for the sample", connector:"php/comboHazard.php" }
php:

require_once("config.php"); require_once("../codebase/connector/combo_connector.php"); $options = new comboConnector($inventory); $options->render_table("hazard","id","name");

How can I set the default value of my combo to the first option of the combo list?
Thanks
Csaba

You can use beforeRender event of Connector to select an option:

function select_first($option){ if ($option->get_index() == 0) { $option->select(); } } $options = new comboConnector($inventory); $options->event->attach("beforeRender","select_first"); $options->render_table("hazard","id","name");

But there was a problem with selection in combo_connector.php. So, please use attached library. select() method will work with it.
combo_connector.zip (1.2 KB)

Awesome :smiley:.Thanks, Alexandra.
Exactly what I needed.

C

What is $inventory?

This is the database connection:
docs.dhtmlx.com/connector__php_ … serverside

Thank you for the code. It made me work a lot easier. It was very helpful to me. พนันออนไลน์