php - Select list first passes others do not -


in www.mpoo.org/organizatori/drugi.php have 2 select list, first time work other no. similar this.

second time debugger say:

typeerror: $(...) null

drugi.php:37

var country_id = $("select#drop1 option:selected").attr('value');

    <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html> <head> <title>Списак организатора</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="style.css" type="text/css" /> <style type="text/css"> <!-- @import url("stil.css");  --> </style>  </head> <body>   <div id="body">     <div class="mhead"><h2>Списак организатора</h2></div>     <div id="dropdowns">        <div id="center" class="cascade">                 <label>Одабери претрагу:                 <select  name="country" id = "drop1">                     <option value=""> Одабери...</option>                     <option value="grad"> Град/Општина</option>                     <option value="zanimanje"> Занимање</option>                     <option value="struka"> Струка</option>                     <option value="organizator"> Организатор</option>                     <option value="svi"> Сви организатори</option>                 </select>                 </label>           </div>         <div class="cascade" id="state"></div>        </div>       <div id="city"> </div>    </div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <script> $(document).ready(function(){ $("select#drop1").change(function(){      var country_id =  $("select#drop1 option:selected").attr('value');  // alert(country_id);        $("#state").html( "" );     $("#city").html( "" );     if (country_id.length > 0 ) {          if (country_id=='svi'){         $.ajax({                 type: "post",                 url: "drugi4.php",                 data: "country_id="+country_id,                 cache: false,                 beforesend: function () {                      $('#state').html('<img src="loader.gif" alt="" width="24" height="24">');                 },                 success: function(html) {                         $("#state").html( html );                 }             });         }          else {           $.ajax({                 type: "post",                 url: "drugi2.php",                 data: "country_id="+country_id,                 cache: false,                 beforesend: function () {                      $('#state').html('<img src="loader.gif" alt="" width="24" height="24">');                 },                 success: function(html) {                         $("#state").html( html );                 }             });         }     } }); }); </script> </body> </html> 

this drugi2.php

    <?php include("connection.php"); //var_dump($_post);  $state_id = trim(mysqli_escape_string($con, $_post["country_id"])); $sql="select distinct $state_id jom_x1_organizatori order $state_id"; $count = mysqli_num_rows( mysqli_query($con, $sql) ); if ($count > 0 ) {     mysqli_set_charset($con, "utf8");     $query = mysqli_query($con, $sql);     ?>     <label>         <select name="city" id = "drop2">             <option value="">Одабери...</option>             <?php while ($rs = mysqli_fetch_array($query, mysqli_assoc)) { ?>             <option value="<?php echo $rs[$state_id]; ?>"><?php echo $rs[$state_id]; ?></option>         <?php } ?>         </select>     </label> <?php  } ?> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <script> $(document).ready(function(){ $("select#drop2").change(function(){      var state_id = $("select#drop2 option:selected").attr('value')+";"+$("select#drop1 option:selected").attr('value'); //    alert(state_id);     if (state_id.length > 0 ) {       $.ajax({             type: "post",             url: "drugi3.php",             data: "state_id="+state_id,             cache: false,             beforesend: function () {                  $('#city').html('<img src="loader.gif" alt="" width="24" height="24">');             },             success: function(html) {                     $("#city").html( html );             }         });     } else {         $("#city").html( "" );     } });  }); </script> 

i think after ajax loading removing selected option, therefore should use:

var country_id = $("#drop1").val();

instead of

var country_id = $("select#drop1 option:selected").attr('value');


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -