Select Combo Box

  • gerry

    gerry - 2011-12-04

    Am trying to implement combo boxes of select drop down lists. 

    When one item is selected in the first select dorp-down list,  the option values shown in the second select drop-dow list should change

    Following examples shown in this forum in various discussions,

    This is the code I have:

            $afood = array( "id" => "F", "desc" => "Fruits" );
    $afood = array( "id" => "N", "desc" => "Nuts" );
    $afood = array( "id" => "V", "desc" => "Vegetables" );
    ->setPk( "id" )

    $afruits = array( "id" => "FA", "desc" => "Apple" );
    $afruits = array( "id" => "FP", "desc" => "Peaches" );
    $afruits = array( "id" => "FG", "desc" => "Grapes" );
    $afruits = array( "id" => "FO", "desc" => "Oranges" );
    ->setPk( "id" )

    $anuts = array( "id" => "NA", "desc" => "Almonds" );
    $anuts = array( "id" => "NC", "desc" => "Cashew" );
    $anuts = array( "id" => "NP", "desc" => "Peanuts" );
    $anuts = array( "id" => "NW", "desc" => "Walnut" );
    ->setPk( "id" )





    public function getCat()

              $foodtype = $this->foods->getValue();

                   if ( $foodtype == "N"  ) {





    This does not work. When an item is selected on the first drop-down, the onChange event does not seem to go to the getCat subroutine.  The option values i the second select list are left unchanged.

    Have tried putting message() statements in the subroutine and I do not see those messages popping up.

    What am I doing worng? Please help…


  • croaker___

    croaker___ - 2011-12-04

    If you're not seeing your message popups, maybe getCat isn't being called? When I have such trouble, I sprinkle around a few:

    /*DEBUG*/ echo "<pre>"; print_r($cols); echo "</pre>";

    Looking at your code…

    You might have more luck with

    $foodtype = $this->foods->get[b]New[/b]Value();

    rather than chaining…

    …assuming "$this->foods" is of type P4A_field, I have more success with:

    $this->intercept($this->foods, "onChange", "getCat");

    Rather than redesigning the whole form ($this->food_form->redesign();), try redesigning just the field:



  • gerry

    gerry - 2011-12-05

    Excellent !  It works now like a charm!

    Thanks Martin for the very helpful and detailed feedback. getCat was not being called in my code.

    What did the trick was:

    $this->intercept($this->foods, "onChange", "getCat");

    Will document this now. Hopefully some time I will be able to put up the documentation of what am learning here.

    P4A is a great application and the developers are doing a great job!



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks