Welcome Guest, Not a member yet? Register   Sign In
Problem with dropdown & jquery

Hi, I try to update three dropdown with ajax (jquery). The problem is that when I select a value from second combo, the third is updated but the second return void (not with the selected value)

Here the code:

class Indicatori extends Controller {

    function Indicatori()
        $this->load->helper(array('form', 'url'));
    function index()
        echo '.';
    function parametri()
    function prova()
        if (isset($_POST['indicatore1']) && $_POST['indicatore1']!='')
             $options ='';
            echo     $options.= '<option value="001" class="dynamic">1value1</option>';
            echo     $options.= '<option value="001" class="dynamic">1value2</option>';
            echo     $options.= '<option value="001" class="dynamic">1value3</option>';
        if (isset($_POST['indicatore2']) && $_POST['indicatore2']!='')
             $options ='';
            echo     $options.= '<option value="001" class="dynamic">2value1</option>';
            echo     $options.= '<option value="001" class="dynamic">2value2</option>';
            echo     $options.= '<option value="001" class="dynamic">2value3</option>';
/* End of file indicatori.php */
/* Location: ./system_osp/application/controllers/indicatori.php */

&lt;title&gt;OSP - Selezione parametri&lt;/title&gt;
function test(step)
    var valore = $("#indicatore" + step).val();
           url: "&lt;?=base_url();?&gt;index.php/indicatori/prova",
           global: false,
           type: "POST",
           async: false,
           dataType: "html",
           data: "indicatore" + step + "="+ valore, //the name of the $_POST variable and its value
           success: function (response) //'response' is the output provided by the controller method prova()
                       //counts the number of dynamically generated options
                       var dynamic_options = $("*").index( $('.dynamic')[0] );
                    //removes previously dynamically generated options if they exists (not equal to 0)
                       if ( dynamic_options != (-1)) $(".dynamic").remove();
                    $("#indicatore" + (step + 1)).show();
                       $("#indicatore" + (step + 1)).append(response);
    return false;
    <h1>OSP - Selezione parametri</h1>

    $attributes = array('class' => 'parametri', 'id' => 'parametri');

    echo form_open('indicatori/parametri', $attributes);
    $options = array();

        $query = $this->db->query('SELECT codice, descrizione FROM indicatori');

        foreach ($query->result_array() as $row)
            $options[$row['codice']] = $row['descrizione'];
    $js = 'id="indicatore1" onChange="test(1)"';
    echo form_dropdown('indicatore1', $options,'TRUE',$js);

    $options = array("000" => "Selezionare");
    $js = 'style="display: none" id="indicatore2" onChange="test(2)"';
    echo form_dropdown('indicatore2', $options,'TRUE',$js);
    $options = array("000" => "Selezionare");
    $js = 'style="display: none" id="indicatore3" onChange="test(3)"';
    echo form_dropdown('indicatore3', $options,'TRUE',$js);
    echo form_close();

Thanks a lot!

[eluser]Ben Edmunds[/eluser]
Sorry I don't have time to go through all the code but try debugging with firebug and by alert()ing the step and the response.

Theme © iAndrew 2016 - Forum software by © MyBB