Onchange to update filed

QuestionsOnchange to update filed
Anand asked 8 years ago

Hi Abu,

I tried to update the field when the option selected from the first field. But its not working for me.

Tried:
——————————————————————-
1st Tried
——————————————————————-
$col["editoptions"] = array(
"value"=>":Select;".$str,
"onchange" => array("sql"=>"select sum(nvl(ADMIN.$runkm.$openkm,0)) as k, sum(nvl(ADMIN.$runkm.$openkm,0)) as v, from ADMIN.$runkm WHERE ADMIN.$runkm.$tyreid = '{tyreid}' and ADMIN.$runkm.$stats ='AA'",
"callback" => "update_fields"));

<script>
function update_fields(data)
{
jQuery("input[name=rethgivenkm].FormElement").val(data[0].rethgivenkm);
jQuery("input[name=rethgivenkm].editable").val(data[0].rethgivenkm);
}
</script>

——————————————————————-
2nd Tried
——————————————————————-

$col["editoptions"] = array(
"value"=>":Select;".$str,
"onchange" => array("sql"=>"select sum(nvl(ADMIN.$runkm.$openkm,0)) as k, sum(nvl(ADMIN.$runkm.$openkm,0)) as v, from ADMIN.$runkm WHERE ADMIN.$runkm.$tyreid = '{tyreid}' and ADMIN.$runkm.$stats ='AA'",
"update_field" =>"rethgivenkm"));

<script>
function update_field()
{
o = jQuery('.ui-search-toolbar select[name=rethgivenkm]').get();
o.event = 'onload'; fx_get_dropdown(o,'rethgivenkm',1);

}
</script>

————————————————————————–

Herewith i have attached the code.

$col = array();
$col["title"] = "Tyre No "; // caption of column
$col["name"] = "tyreid"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["dbname"] = "tyreid"; // this is required as we need to search in name field, not id
$col["width"] = "80";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$tyreid='"tyreid"';
$tyrename='"tyreno"';
$tts='"veh_tyredetails"';
$stats = '"status"';
$runkm='"veh_tyrerunningkm"';
$openkm='"openkm"';
$col["isnum"] = true;
$col["isnull"] = true;
$str = $g->get_dropdown_values("select $tyreid as k,$tyrename as v from ADMIN.$tts where $stats='AA'");
$col["editoptions"] = array(
"value"=>":Select;".$str,
"onchange" => array("sql"=>"select sum(nvl(ADMIN.$runkm.$openkm,0)) as k, sum(nvl(ADMIN.$runkm.$openkm,0)) as v, from ADMIN.$runkm WHERE ADMIN.$runkm.$tyreid = '{tyreid}' and ADMIN.$runkm.$stats ='AA'",
"callback" => "update_fields"));
$col["editoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_leave1('{$col["name"]}'); },200); }";

$col["stype"] = "select";

$col["searchoptions"] = array("value" => ":;".$str);
$col["searchoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_leave1('gs_{$col["name"]}'); },350); }";

$col["formatter"] = "select"; // display label, not value
$col["editrules"] = array("enable"=>false);
$col["formoptions"] = array("rowpos"=>"1", "colpos"=>"1") ;
$cols[] = $col;

$col = array();
$col["title"] = "Retreading Given Dt."; // caption of column
$col["name"] = "rethgivendt"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["editable"] = true;
$col["search"] = true;
$col["isnull"] = true;
//$col["editrules"] = array("required"=>true);
$col["width"] = "60";
$col["formatter"] = "date"; // format as date
//$col["editrules"] = array("custom"=>true,"custom_func"=>"function(val,label){return my_validation(val,label);}");
$col["search"] = true;
$col["editrules"] = array("edithidden"=>true,"required"=>true);
$col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'Y-m-d');
$col["formoptions"] = array("rowpos"=>"1", "colpos"=>"2") ;
$col["show"] = array("list"=>true,"edit"=>true,"add"=>true);
$cols[] = $col;

Thank you,

4 Answers
Anand answered 8 years ago

Hi Abu,

Sorry wrongly posted coding

Herewith i have attached the code.

$col = array();
$col["title"] = "Tyre No "; // caption of column
$col["name"] = "tyreid"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["dbname"] = "tyreid"; // this is required as we need to search in name field, not id
$col["width"] = "80";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$tyreid='"tyreid"';
$tyrename='"tyreno"';
$tts='"veh_tyredetails"';
$stats = '"status"';
$runkm='"veh_tyrerunningkm"';
$openkm='"openkm"';
$col["isnum"] = true;
$col["isnull"] = true;
$str = $g->get_dropdown_values("select $tyreid as k,$tyrename as v from ADMIN.$tts where $stats='AA'");
$col["editoptions"] = array(
"value"=>":Select;".$str,
"onchange" => array("sql"=>"select sum(nvl(ADMIN.$runkm.$openkm,0)) as k, sum(nvl(ADMIN.$runkm.$openkm,0)) as v, from ADMIN.$runkm WHERE ADMIN.$runkm.$tyreid = '{tyreid}' and ADMIN.$runkm.$stats ='AA'",
"callback" => "update_fields"));
$col["editoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_leave1('{$col["name"]}'); },200); }";

$col["stype"] = "select";

$col["searchoptions"] = array("value" => ":;".$str);
$col["searchoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_leave1('gs_{$col["name"]}'); },350); }";

$col["formatter"] = "select"; // display label, not value
$col["editrules"] = array("enable"=>false);
$col["formoptions"] = array("rowpos"=>"1", "colpos"=>"1") ;
$cols[] = $col;

$col = array();
$col["title"] = "Retreading Given KM";
$col["name"] = "rethgivenkm";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["isnull"] = true;
//$col["editrules"] = array("required"=>)false;
$col["width"] = "60";
$col["hidden"] = true;
$col["editrules"] = array("number"=>true);
$col["formoptions"] = array("rowpos"=>"7", "colpos"=>"1") ;
$col["show"] = array("list"=>true,"edit"=>true,"add"=>true);
$cols[] = $col;

Abu Ghufran answered 8 years ago

$col["editoptions"] = array(
"value"=>":Select;".$str,
"onchange" => array("sql"=>"…",
"callback" => "update_fields"));

The sql must contains columns that you want to use in callback function.
Here 'rethgivenkm' is not found in sql.

select sum(nvl(ADMIN.$runkm.$openkm,0)) as k, sum(nvl(ADMIN.$runkm.$openkm,0)) as v, from ADMIN.$runkm WHERE ADMIN.$runkm.$tyreid = '{tyreid}' and ADMIN.$runkm.$stats ='AA'

Please refer demos/appearance/dropdown-callback.php. we use query:

"onchange" => array(
"sql"=>"select * from clients",
"search_on"=>"name",
"callback" => "fill_form" )

and then used selected fields in callback function.

Anand answered 8 years ago

Hi Abu,

Thank you for your reply.

But In onchange of column select I want to sum particular column in sql query and want to use the result in next field.

sum(nvl(ADMIN.$runkm.$openkm,0))

How to use this.

Thank you

Abu Ghufran answered 8 years ago

Hello,

It's upto you to write query that return SUM(…) as field as well as other fields to be populated.
You can then use select columns in callback functions.

Your Answer

18 + 4 =

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?