Welcome Guest, Not a member yet? Register   Sign In
Help, JAVASCRIPT not working in CI...
#1

[eluser]Gewa[/eluser]
Hi In my application I have a .php file which is working separetly direcly with DB to take data from there and make chained selects.



ajax.functions.php
Code:
// Get regions options

    if (isset($_GET["func"]) and $_GET["func"] == 'get_regions' and isset($_GET["value"])) {



        $res = $db->query("SELECT id, region FROM region WHERE country_id = '".$_GET["value"]."' ORDER BY region");



        $options = '';



        if ($_GET["value"] != '0') while ($line = $res->fetch($res)) {



            $options .= "selbox.options[selbox.options.length] = new Option('".$line["region"]."','".$line["id"]."');";

        }



        echo "var selbox = ".$_GET["sel"].";

        selbox.options.length = 0;

        selbox.options[selbox.options.length] = new Option('Выберите Регион','0');

        ".$options;

    }



    // Get ciries options

    if (isset($_GET["func"]) and $_GET["func"] == 'get_cities' and isset($_GET["value"])) {



        $res = $db->query("SELECT id, city FROM city WHERE region_id = '".$_GET["value"]."'");



        $options = '';



        if ($_GET["value"] != '0') while ($line = $res->fetch($res)) {



            $options .= "selbox.options[selbox.options.length] = new Option('".$line["city"]."','".$line["id"]."');";

        }



        echo "var selbox = ".$_GET["sel"].";

        selbox.options.length = 0;

        selbox.options[selbox.options.length] = new Option('Выберите Город','0');

        ".$options;

    }



    // Get subcategories checkboxes

    if (isset($_GET["func"]) and $_GET["func"] == 'get_subcats' and isset($_GET["value"])) {



        $options = '';




$res = $db->query("SELECT id, category_name  FROM t_categories WHERE  parent_id = '".$_GET["value"]."'");



        if ($_GET["value"] != '0') while ($line = $res->fetch($res)) {



            $options .= "selbox.options[selbox.options.length] = new Option('".$line["category_name"]."','".$line["id"]."');";

        }



        echo "var selbox = ".$_GET["sel"].";

        selbox.options.length = 0;

        selbox.options[selbox.options.length] = new Option('Выберите подкатегорию','0');

        ".$options;

    }

here is main code, beforethat comes connection and class for working with mysql.

ajax.js which is below is making parsing as I understand

Code:
function ajax_do (url) {
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url + '&t;=<? echo time();?>';
        document.body.appendChild (jsel);
        return true;
    }

And I have selects

Code:
<select name="country">
                                <option value=0 selected>Choose Country</option>


     &lt;? $this->db->select('*');
      $this->db->from('country');


       $query= $this->db->get();
      foreach($query->result_array() as $row){
          $id=$row['id'];
          $cat_name=$row['country'] ;
       echo"       <option value=\"$id\">$cat_name</option>  ";

           }
       ?&gt;

</select>



        Region       <select name="region"></select>

City<select name="city"></select>


What is the best way to put functions of calling region and city in CI?
I have tried to put them in controlley ajax_functions.php

and call like thisonChange="ajax_do('/ajax_functions/get_cities/'+this.value+'/document.add_tender.city');" />

and I have made in ajax_functions like this
Code:
function get_cities($value,$sel){




        $res = $this->db->query("SELECT id, city FROM city WHERE region_id = '".$_GET["value"]."'");



        $options = '';



        if ($value != '0') {


          foreach ($res->result_array() as $line) {



            $options .= "selbox.options[selbox.options.length] = new Option('".$line["city"]."','".$line["id"]."');";

          }
        }


        echo "var selbox =$sel;

        selbox.options.length = 0;

        selbox.options[selbox.options.length] = new Option('Choose City','0');

        ".$options;


   }

Not working Sad What's up?




Theme © iAndrew 2016 - Forum software by © MyBB