Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14348

Select tag dropdown dependence to next select tag.

$
0
0
Hello everybody, I am new in codeIgniter, but I really want to learn it. 

Right now I am trying to make a small cms for car accessories search by vehicle or car brand, model or engine.  But i stuck with Ajax-code igniter. 
I am looking for someone who can help me. I will be really grateful for help. Please if some one have an answer - help me to find solution.

That is my StackOverFlow QueThats my Stackoverflow questionstion: 
http://stackoverflow.com/questions/39995...9#39998639


What i want to do? I want to make few select tags with options. When user select something in first <select>tag (dropdown) (e.g. value from "categories" select list), second <select> tag get some values . Its like dependence. 

e.g. I have a list of vehicles categories: car, motorcycle, boat  etc. and when I choose one of them (e.g. car) in select tag, the other select tag shows us Audi, BMW, Mercedes etc...

But my code isn't working? can somebody help me please? 
 
And here its my code: 

Controller: models.php (.../public_html/test/testcms/application/controllers/admin)

PHP Code:
public function get_data()
{
 
   $value $this->input->post("value");
 
   $data $this->Model_model->get_data($value);
 
   $option ="";
 
   foreach($data as $d)
 
   {
 
       $option .= "<option value='".$d->id."' >".$d->v_model_name."</option>";
 
   }
 
   echo $option;
 
   $data['main_content'] = 'admin/models/add';
 
   $this->load->view("admin/models/add"$data);




Model: Model_model (.../public_html/test/testcms/application/models)



PHP Code:
   public function get_data($value)
{
 
   $this->db->where("id",$value);
 
   return $this->db->get("vehicle_models")->result();



View: add.php (/public_html/test/testcms/application/views/admin/models)


PHP Code:
Hello everybodyI am new in codeIgniterbut I really want to learn it

Right now I am trying to make a small cms for car accessories search by vehicle or car brandmodel or engine But i stuck with Ajax-code igniter
I am looking for someone who can help meI will be really grateful for helpPlease if some one have an answer help me to find solution.

That is my StackOverFlow Question
http://stackoverflow.com/questions/39995223/code-igniter-select-tag-option-depending-on-another-select-tag-value/39998639#39998639

And here its my code

Controllermodels.php (.../public_html/test/testcms/application/controllers/admin)
public function 
get_data()
{
 
   $value $this->input->post("value");
 
   $data $this->Model_model->get_data($value);
 
   $option ="";
 
   foreach($data as $d)
 
   {
 
       $option .= "<option value='".$d->id."' >".$d->v_model_name."</option>";
 
   }
 
   echo $option;
 
   $data['main_content'] = 'admin/models/add';
 
   $this->load->view("admin/models/add"$data);
}


ModelModel_model (.../public_html/test/testcms/application/models)

 
   public function get_data($value)
{
 
   $this->db->where("id",$value);
 
   return $this->db->get("vehicle_models")->result();
}


Viewadd.php (/public_html/test/testcms/application/views/admin/models)

<?
php echo validation_errors('<p class="alert alert-dismissable alert-danger">'); ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form method="post" action="<?php echo base_url(); ?>admin/models/add">
    <div class="row">
        <div class="col-lg-6">
            <h1>Insert Model</h1>
        </div>
        <div class="col-lg-6">
            <div class="btn-group pull-right">
                <input type="submit" name="submit" class="btn btn-success" value="Save">
                <a href="<?php echo base_url(); ?>admin/models" class="btn btn-default">Close</a>
            </div>
        </div>
    </div><!-- /.row -->
    <div class="row">
        <div class="col-lg-12">
            <ol class="breadcrumb">
                <li><a href="<?php echo base_url(); ?>admin/dashboard"><i class="fa fa-dashboard"></i>Dashboard</a></li>
                <li><a href="<?php echo base_url(); ?>admin/dashboard"><i class="fa fa-pencil"></i>Models</a></li>
                <li class="active"><i class="fa fa-plus-square-o"></i>Insert Model</li>
            </ol>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <h2>Insert Model</h2>
            <div class="form-group">
                <label>Model name</label>

                <input class="form-control" type="text" name="model" value="<?php echo set_value('model'); ?>" placeholder="Model" >
            </div>
            <!-- *** Category *** -->
            <div class="form-group">
                <label>Category</label>
                <select name="category" id="categoryid" class="form-control">
                    <option value="">Choose Category</option>
                    <?php foreach($categories as $category) : ?>
                        <option value="<?php echo $category->id?>"><?php echo $category->category_name?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <!-- *** Brand *** Choose brand-->
            <div class="form-group">
                <label>Brand</label>
                <select name="brand" id="brand_id" class="form-control">
                </select>
                </div>
            </div>
        </div>
<script>


    $("#category_id").on("change",function(){
        var value = $(this).val();
        $.ajax({
            url : "http://paieska.alyvatau.lt/turinio_valdymas/admin/models/add",
            type: "post",
            data: {"value":value},
            success : function(data){
                $("#brand_id").html(data);
            },
        });
    })

</script> 

Viewing all articles
Browse latest Browse all 14348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>