0

Hi,

i'm working on a website where i have to edit products. but first i have to select a Simulator and inside that simulator i have a several products.

What i want to do is, select a Simulator on a combobox and then in other combobox appears me all products that belong to that simulator.

Do you understand?

Here's my code:

Onchange Script:

<!--COMBO to COMBO-->
<script>
        $("select #simul").change(function () {
                  var str = "";
                  $("select #simul option:selected").each(function () {
                                str += $(this).text() + " ";
                          });
                  $("select .simulador").text(str);
                })
                .change();
</script>


<!--COMBO to TEXTBOX-->
<script>
        $("select.simulador").change(function () {
                  var str = "";
                  $("select.simulador option:selected").each(function () {
                                str += $(this).text() + " ";
                          });
                  $("div .change_name").text(str);
                })
                .change();
</script>
<!----------------------------------------------->

Form:

    <?php 
        $query_simulador=mysql_query("SELECT * FROM simulador") or die(mysql_error());
        $titulo_sim=mysql_num_rows($query_simulador);

        $query_prod_sim=mysql_query("SELECT * FROM produtos WHERE id_simulador='".$titulo_sim['id_simulador']."'") or die(mysql_error());
        $prod_sim=mysql_fetch_assoc($query_prod_sim);
    ?>
    <label for="edit-name" id="simul" class="label-help">Simulador: </label>
    <select class="inp-form big_inp" name="simulador" id="titulo">
        <?php 
        while ($titulo_sim=mysql_fetch_assoc($query_simulador))
        {
        ?>
            <option <?php if($simulador['titulo_simulador']==$titulo_sim['titulo_simulador']){echo 'selected="selected"';} ?>> <?php echo $titulo_sim['titulo_simulador']; ?> </option>
        <?php
        ;}
        ?>
    </select>
    <div class="description">O nome de leitura fácil, deste tipo de conteúdo. Este texto será mostrado como parte da lista na página criar conteúdo. É recomendado que este nome comece com uma letra maiúscula e contenha apenas letras, números e espaços. Este nome tem de ser único.</div>
    <br />

            <label for="edit-name" class="label-help">Produto: </label>
    <table>
    <tr>
        <td>
            <input type="text" name="prod_name">
                <div class="change_name" style="margin-top:-17px; margin-left:5px;"> </div>
            </input>
        </td>

        <td width="20px"></td>

        <td>
            <select onchange="function()" name="produtos" class="simulador">
                <option>

                </option>
            </select>
        </td>
    </tr>
    </table>

Thank you,
PF2G

3
Contributors
3
Replies
23
Views
5 Years
Discussion Span
Last Post by LastMitch
0

What i want to do is, select a Simulator on a combobox and then in other combobox appears me all products that belong to that simulator.

You never mention any errors? What error messages you get? I don't see anything wrong with the code. The only thing is the database is connected? Does your query fetch the data? This is as much I can help you with this.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.