Select Onchange

QuestionsSelect Onchange
BuiDuongThe asked 10 years ago

// Code //
$col = array();
$col["title"] = "Client";
$col["name"] = "client_id";
$col["dbname"] = "clients.client_id";
$col["width"] = "100";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select";
# fetch data from database, with alias k for key, v for value

# on change, update other dropdown
$str = $g->get_dropdown_values("select client_id as k, name as v from clients");
$col["editoptions"] = array(
"value"=>$str,
"onchange" => array("sql"=>"select id as k, note as v from invheader WHERE client_id = '{client_id}'",
"update_field" => "note" )
);

$col["formatter"] = "select"; // display label, not value
$col["stype"] = "select";
$col["searchoptions"] = array("value" => ":;".$str);

$cols[] = $col;

$col = array();
$col["title"] = "Invoices";
$col["name"] = "note";
$col["width"] = "100";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select";
$str = $g->get_dropdown_values("select id as k, note as v from invheader");
$col["editoptions"] = array("value"=>$str);

$col["editoptions"]["onload"]["sql"] = "select id as k, note as v from invheader WHERE client_id = {client_id}";
$col["stype"] = "select";
$col["searchoptions"] = array("value" => ":;".$str);

$cols[] = $col;
// Code //

When I onchange not working, help fix problem

thanks

3 Answers
Abu Ghufran answered 10 years ago

This is supported in premium verison. If you are already using it, please check demos/appearance/dropdown-dependent.php

Antonis Kosmopoulos answered 9 years ago

This works great in the add/edit form, but on the grid the dropdown is always full of all possible values, i.e. it does not update with the "onchange" event. Is there a way to do that?

Abu Ghufran answered 9 years ago

You will need to add following along with onchange:

$col["editoptions"]["onload"]["sql"] = "select distinct client_id as k, name as v from clients";

Cpde: http://phpgrid.org/demo/demos/appearence/dropdown-dependent.phps

Your Answer

19 + 7 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?