Open Dropdown according to another loop Dropdown

1

This script does the following: when we click on the first dropdown it opens a second dropdown.

Ok, so far it works perfectly. But my problem is that when I put it inside a loop it stops working.

So each line wanted me to repeat this script. As I am not aware of javascript I wanted a little help to solve this

select.php

<script type="text/javascript"   
 src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><scripttype="text/javascript">
 $(document).ready(function() {
 $('#loader').hide();
 $('#show_heading').hide();
 $('#search_category_id').change(function(){
    $('#show_sub_categories').fadeOut();
    $('#loader').show();
    $.post("select2.php", {
        parent_id: $('#search_category_id').val(),
    }, function(response){
        setTimeout("finishAjax('show_sub_categories',   
 '"+escape(response)+"')", 400);
    });
    return false;

    });

    });
    function finishAjax(id, response){
    $('#loader').hide();
    $('#show_heading').show();
    $('#'+id).html(unescape(response));
    $('#'+id).fadeIn();
    } 
    function alert_id()
    {
    if($('#sub_category_id').val() == '')
    alert('Please select a sub category.');
    else
    alert($('#sub_category_id').val());
    return false;
    }
    </script>



    Cliente:
    <select name="id_solicitante"  class="form-control"     
    id="search_category_id" required >
    <option value="" selected="selected"></option>
    <option value="1">Cliente</option>
    <?php
    $query = "select * from empresas where id_transfer = $id_transfer";
    $results = mysql_query($query);
    while ($rows = mysql_fetch_assoc(@$results))
    {?>
        <option value="<?php echo $rows['id_empresa'];?>"><?php echo   
    $rows['nome_fan'];?></option>
    <?php
    }?>
    </select>
    </div>
    <div id="show_sub_categories" align="center"></div>

select2.php

     <?php

     if($_REQUEST)
     {?>

    <?php    
    $id     = $_REQUEST['parent_id'];
    $query = "select * from usuarios where id_empresa = ".$id;
    $results = mysql_query( $query);?>
    Solicitante:
    <select name="user_soli" class="form-control" id="sub_category_id">
    <option value="" selected="selected"></option>
    <?php
    while ($rows = mysql_fetch_assoc(@$results))
    {?>
    <option value="<?php echo $rows['id_user'];?>"><?php echo     
    $rows['nome'];?></option>
    <?php
    }}?>
    </select>  
    
asked by anonymous 25.08.2015 / 21:31

0 answers