Combo default value from php connector

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

{ type: "combo", name: "hazard", label: "Hazard: ", inputWidth: 250, tooltip: "Select the appropriate hazard for the sample", connector:"php/comboHazard.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?

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. (1.2 KB)

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


What is $inventory?

This is the database connection: … serverside

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