Onchange event with two selects

Asked

Viewed 120 times

0

Good guys, gave problem. ajax function to trying to load a list of clients and each client exists a property to create reports.

Ajax code:

function CarregaPropriedades(Cliente)
{
    if(Cliente){
        var myAjax = new Ajax.Updater("PropriedadesAjax","buscar_propriedades.php?pesquisador="+Cliente,
        {
            method : "get"
        }) ;
    }

}

Code for search properties.

<?
    $cliente = $_GET['pesquisador'];
    $dao = new Propriedade();
    $listar_com_pesquisador = $dao->listar_propriedades_cliente($cliente);
?>
<select name="propriedade" id="propriedade">
    <?php foreach($listar_com_pesquisador as $res){
    ?>
        <option value="<?php echo $res->Id?>"><?php echo $res->Nome?></option>
<?php }?>
</select>

I debug with firebug in firefox shows the following error.

Referenceerror: Ajax is not defined

Loadproperties()form_bo...Olo.php (line 73)

onchange()form_bo...Olo.php (line 1)

myAjax = new Ajax.Updater("Propriedadesajax","buscar_properties.php? researcher="...

And now? I don’t know what to do, waiting for opinions and suggestions for resolutions.

1 answer

0

I had even forgotten to answer, but it was solved The Prototype library was inserted and resolved this issue. The complete code to load a customer and a property specifies according to the selected customer: $edit variables come from the $_GET that receives the client ID if the administrator wants to edit it.

    <div class="form-inline">
        <label>Selecione um cliente:</label>
        <select style="min-width:65%" onchange="CarregaPropriedades(this.value)"  name="Id_cliente" id="Clientess" class="form-control">    
            <option> Selecione o cliente </option>
            <?php foreach ($clientes as $cliente) { ?>  

                <option <?php
                if (isset($editar)) {
                    if ($boletim->Id_cliente == $cliente->Id) {
                        echo "selected=selected";
                        $cliente_selecionado = $cliente->Id;
                    }
                }
                ?>

                    style="width: 900px;" name="<?php echo $cliente->Id; ?>" value="<?php echo $cliente->Id; ?>" ><?php echo $cliente->Nome; ?></option>
                }
            <?php } ?>
        </select>
        <a href="form_cliente.php" class="btn btn-info" role="button">Cadastrar novo cliente</a>
    </div>

    <hr />


    <div class="form-inline" id="PropriedadesAjax">
        <label>Selecione uma propriedade:</label>
        <select style="min-width:61.2%" name="Propriedade" id="Propriedade" class="form-control">    

            <?php
            if (isset($editar)) {
                $propriedades = $daoPropriedades->listar_propriedades_cliente($cliente_selecionado);
                foreach ($propriedades as $propriedade) {
                    ?> 
                    <option   <?php
            if ($boletim->Propriedade == $propriedade->Id) {
                echo "selected=selected";
            }
                    ?> value="<?php echo $propriedade->Id; ?>" name="Propriedade" id="Propriedade"><?php echo $propriedade->Nome; ?></option>  
                        <?php
                    }
                } else {
                    echo '<option value="">Selecione a propriedade</option>';
                }
                ?>
        </select>

    </div>

    <hr />

    <div class="form-inline">
        <label>Selecione um pesquisador:</label>
        <select style="min-width:61.56%" name="Pesquisador" id="Pesquisador" class="form-control">    
            <option> Selecione um pesquisador responsável </option>
            <?php foreach ($pesquisadores as $pesquisador) { ?>  

                <option <?php
                if (isset($editar)) {
                    if ($boletim->Pesquisador == $pesquisador->Login) {
                        echo "selected=selected";
                    }
                }
                ?>

                    style="width: 750px;" id="optionCliente" name="<?php echo $pesquisador->Login; ?>" value="<?php echo $pesquisador->Login; ?>" ><?php echo $pesquisador->Login; ?></option>

            <?php } ?>
        </select>
        <a href="form_pesquisador.php" class="btn btn-info" role="button">Cadastrar novo pesquisador</a>
    </div>

Any questions just ask me about.

  • http://imgur.com/KbMxj57 .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.