0

I added a script to my website that generates a chained selection system. It works ok but when I tried to fetch the data in to my search script I realized that it won't generate any source code that I can use. I attach you the parts that I think are important to be able to fix this problem. Please let me know before downrating. Thanks!

<script type="text/javascript">
$(document).ready(function() {
    $('#wait_1').hide();
    $('#judet').change(function(){
      $('#wait_1').show();
      $('#result_1').hide();
      $.get("func.php", {
        func: "judet",
        drop_var: $('#judet').val()
      }, function(response){
        $('#result_1').fadeOut();
        setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
      });
        return false;
    });
});

function finishAjax(id, response) {
  $('#wait_1').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}
</script>

The HTML part:

<tr>
                                        <td><label>Judet</label></td>
                                        <td><select name="judet" id="judet">
                                                <option value="" selected="selected" disabled="disabled">Selecteaza judetul</option>
                                                 <?php getTierOne(); ?>
                                            </select></td>                                                                          
                                    <tr>
                                        <td><label>Localitate</label></td>
                                        <td>
                                            <span id="wait_1" style="display: none;"><img alt="Asteptati..." src="images/ajax-loader.gif"/></span> 
                                            <span id="result_1" style="display: none;"></span>
                                        </td>
                                    </tr>

The PHP part:

function judet($drop_var)
{  
    include_once('mysql_connect.php');
    $result = mysql_query("SELECT * FROM orase WHERE judet='$drop_var'") 
or die(mysql_error());

echo '<select name="tier_two" id="tier_two">
      <option value=" " disabled="disabled" selected="selected">Selecteaza localitatea</option>';

       while($drop_2 = mysql_fetch_array( $result )) 
        {   
          echo '<option value="'.$drop_2['oras'].'">'.$drop_2['oras'].'</option>';
        }

echo '</select>';
}
MrCode
  • 63,975
  • 10
  • 90
  • 112
SporeDev
  • 608
  • 1
  • 8
  • 26
  • Are you referring to something like this http://stackoverflow.com/questions/1750865/best-way-to-view-generated-source-of-webpage? – Mattt Aug 15 '13 at 18:47
  • Yeah, I think so. But it still doesn't provide me with an answer, just a few useful information. – SporeDev Aug 15 '13 at 19:09

1 Answers1

0

In my case the problem was relatively simple but that didn't stopped me to keep trying for the whole day to find a solution. I learned a few things today and now my script is working so it's all good in the end. All I had to do was to add another hidden input in the html part like this:

<input type='hidden' name="locatie" value="<?php echo $_POST['tier_two']; ?>" >

Then I was able to get it's value and use it where I wanted using a variable that was equal to $_POST['tier_two'];. In case you run in to this problem note that Ajax will not display your source code as you would expect, you will need Firebug or a similar tool. However, this time I solved my problem without using one. Good luck!

SporeDev
  • 608
  • 1
  • 8
  • 26