Combobox based on another combobox












0















I'm trying to do the following. I am selecting an item from a combobox then I want the values of the next combobox to be the result of a query based on the first selection. This is what I have so far.... HTML



    <fieldset>
<div class="form-group">
<select class="custom-select" name="serviciuSelect" id="serviciuSelect" onchange="arataAngajat()">
<option selected="">Selecteaza serviciul dorit</option>
<?php foreach ($servicii as $item): ?>
<option value="<?php echo $item['denumire']; ?>"><?php echo $item['denumire']; ?></option>
<?php endforeach;?>
</select>
</div>
</fieldset>

<fieldset>
<div class="form-group">
<select class="custom-select" name="angajatSelect" id="angajatSelect" style="visibility: hidden">
<option selected="">Selecteaza angajatul dorit</option>
<!-- <?php foreach ($angajati as $item): ?>
<option value="<?php echo $item['nume']; ?>"><?php echo $item['nume']; ?></option>
<?php endforeach;?> -->
</select>
</div>
</fieldset>


JavaScript



    <script>
function arataAngajat() {
document.getElementById("angajatSelect").style.visibility = "visible";
var e = document.getElementById("serviciuSelect").value;
document.cookie = "selectSer = " + e;
}
</script>


PHP



    <?php 
function getSelectServiciu(){
$selectServiciu= $_COOKIE['selectSer'];
$query = "SELECT COD_A FROM angajat WHERE COD_A IN (
SELECT COD_A FROM angajat_serviciu WHERE COD_S='".
$selectServiciu."')";
$result = $this->db->query($query)->result_array();
return $result;
}
?>


I got stuck when I had to call the PHP function getSelectServiciu(). Also, If there's a better way of doing this, please let me know.



Thanks,
Tibi










share|improve this question























  • The JavaScript and cookie will be on the client side, the PHP executes on the server. You need to 'post' or 'get' the cookie info to the server then run your PHP when you receive and process this.

    – SPlatten
    Nov 22 '18 at 11:39













  • did you check value of $_COOKIE['selectSer']

    – Mahfuzar Rahman
    Nov 22 '18 at 11:39











  • i have all the code on the same page. should i create a separate php file to handle this query? and how to call this function when changing the item in combobox?

    – Tibi
    Nov 22 '18 at 11:45
















0















I'm trying to do the following. I am selecting an item from a combobox then I want the values of the next combobox to be the result of a query based on the first selection. This is what I have so far.... HTML



    <fieldset>
<div class="form-group">
<select class="custom-select" name="serviciuSelect" id="serviciuSelect" onchange="arataAngajat()">
<option selected="">Selecteaza serviciul dorit</option>
<?php foreach ($servicii as $item): ?>
<option value="<?php echo $item['denumire']; ?>"><?php echo $item['denumire']; ?></option>
<?php endforeach;?>
</select>
</div>
</fieldset>

<fieldset>
<div class="form-group">
<select class="custom-select" name="angajatSelect" id="angajatSelect" style="visibility: hidden">
<option selected="">Selecteaza angajatul dorit</option>
<!-- <?php foreach ($angajati as $item): ?>
<option value="<?php echo $item['nume']; ?>"><?php echo $item['nume']; ?></option>
<?php endforeach;?> -->
</select>
</div>
</fieldset>


JavaScript



    <script>
function arataAngajat() {
document.getElementById("angajatSelect").style.visibility = "visible";
var e = document.getElementById("serviciuSelect").value;
document.cookie = "selectSer = " + e;
}
</script>


PHP



    <?php 
function getSelectServiciu(){
$selectServiciu= $_COOKIE['selectSer'];
$query = "SELECT COD_A FROM angajat WHERE COD_A IN (
SELECT COD_A FROM angajat_serviciu WHERE COD_S='".
$selectServiciu."')";
$result = $this->db->query($query)->result_array();
return $result;
}
?>


I got stuck when I had to call the PHP function getSelectServiciu(). Also, If there's a better way of doing this, please let me know.



Thanks,
Tibi










share|improve this question























  • The JavaScript and cookie will be on the client side, the PHP executes on the server. You need to 'post' or 'get' the cookie info to the server then run your PHP when you receive and process this.

    – SPlatten
    Nov 22 '18 at 11:39













  • did you check value of $_COOKIE['selectSer']

    – Mahfuzar Rahman
    Nov 22 '18 at 11:39











  • i have all the code on the same page. should i create a separate php file to handle this query? and how to call this function when changing the item in combobox?

    – Tibi
    Nov 22 '18 at 11:45














0












0








0








I'm trying to do the following. I am selecting an item from a combobox then I want the values of the next combobox to be the result of a query based on the first selection. This is what I have so far.... HTML



    <fieldset>
<div class="form-group">
<select class="custom-select" name="serviciuSelect" id="serviciuSelect" onchange="arataAngajat()">
<option selected="">Selecteaza serviciul dorit</option>
<?php foreach ($servicii as $item): ?>
<option value="<?php echo $item['denumire']; ?>"><?php echo $item['denumire']; ?></option>
<?php endforeach;?>
</select>
</div>
</fieldset>

<fieldset>
<div class="form-group">
<select class="custom-select" name="angajatSelect" id="angajatSelect" style="visibility: hidden">
<option selected="">Selecteaza angajatul dorit</option>
<!-- <?php foreach ($angajati as $item): ?>
<option value="<?php echo $item['nume']; ?>"><?php echo $item['nume']; ?></option>
<?php endforeach;?> -->
</select>
</div>
</fieldset>


JavaScript



    <script>
function arataAngajat() {
document.getElementById("angajatSelect").style.visibility = "visible";
var e = document.getElementById("serviciuSelect").value;
document.cookie = "selectSer = " + e;
}
</script>


PHP



    <?php 
function getSelectServiciu(){
$selectServiciu= $_COOKIE['selectSer'];
$query = "SELECT COD_A FROM angajat WHERE COD_A IN (
SELECT COD_A FROM angajat_serviciu WHERE COD_S='".
$selectServiciu."')";
$result = $this->db->query($query)->result_array();
return $result;
}
?>


I got stuck when I had to call the PHP function getSelectServiciu(). Also, If there's a better way of doing this, please let me know.



Thanks,
Tibi










share|improve this question














I'm trying to do the following. I am selecting an item from a combobox then I want the values of the next combobox to be the result of a query based on the first selection. This is what I have so far.... HTML



    <fieldset>
<div class="form-group">
<select class="custom-select" name="serviciuSelect" id="serviciuSelect" onchange="arataAngajat()">
<option selected="">Selecteaza serviciul dorit</option>
<?php foreach ($servicii as $item): ?>
<option value="<?php echo $item['denumire']; ?>"><?php echo $item['denumire']; ?></option>
<?php endforeach;?>
</select>
</div>
</fieldset>

<fieldset>
<div class="form-group">
<select class="custom-select" name="angajatSelect" id="angajatSelect" style="visibility: hidden">
<option selected="">Selecteaza angajatul dorit</option>
<!-- <?php foreach ($angajati as $item): ?>
<option value="<?php echo $item['nume']; ?>"><?php echo $item['nume']; ?></option>
<?php endforeach;?> -->
</select>
</div>
</fieldset>


JavaScript



    <script>
function arataAngajat() {
document.getElementById("angajatSelect").style.visibility = "visible";
var e = document.getElementById("serviciuSelect").value;
document.cookie = "selectSer = " + e;
}
</script>


PHP



    <?php 
function getSelectServiciu(){
$selectServiciu= $_COOKIE['selectSer'];
$query = "SELECT COD_A FROM angajat WHERE COD_A IN (
SELECT COD_A FROM angajat_serviciu WHERE COD_S='".
$selectServiciu."')";
$result = $this->db->query($query)->result_array();
return $result;
}
?>


I got stuck when I had to call the PHP function getSelectServiciu(). Also, If there's a better way of doing this, please let me know.



Thanks,
Tibi







javascript php html






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 11:34









TibiTibi

12




12













  • The JavaScript and cookie will be on the client side, the PHP executes on the server. You need to 'post' or 'get' the cookie info to the server then run your PHP when you receive and process this.

    – SPlatten
    Nov 22 '18 at 11:39













  • did you check value of $_COOKIE['selectSer']

    – Mahfuzar Rahman
    Nov 22 '18 at 11:39











  • i have all the code on the same page. should i create a separate php file to handle this query? and how to call this function when changing the item in combobox?

    – Tibi
    Nov 22 '18 at 11:45



















  • The JavaScript and cookie will be on the client side, the PHP executes on the server. You need to 'post' or 'get' the cookie info to the server then run your PHP when you receive and process this.

    – SPlatten
    Nov 22 '18 at 11:39













  • did you check value of $_COOKIE['selectSer']

    – Mahfuzar Rahman
    Nov 22 '18 at 11:39











  • i have all the code on the same page. should i create a separate php file to handle this query? and how to call this function when changing the item in combobox?

    – Tibi
    Nov 22 '18 at 11:45

















The JavaScript and cookie will be on the client side, the PHP executes on the server. You need to 'post' or 'get' the cookie info to the server then run your PHP when you receive and process this.

– SPlatten
Nov 22 '18 at 11:39







The JavaScript and cookie will be on the client side, the PHP executes on the server. You need to 'post' or 'get' the cookie info to the server then run your PHP when you receive and process this.

– SPlatten
Nov 22 '18 at 11:39















did you check value of $_COOKIE['selectSer']

– Mahfuzar Rahman
Nov 22 '18 at 11:39





did you check value of $_COOKIE['selectSer']

– Mahfuzar Rahman
Nov 22 '18 at 11:39













i have all the code on the same page. should i create a separate php file to handle this query? and how to call this function when changing the item in combobox?

– Tibi
Nov 22 '18 at 11:45





i have all the code on the same page. should i create a separate php file to handle this query? and how to call this function when changing the item in combobox?

– Tibi
Nov 22 '18 at 11:45












1 Answer
1






active

oldest

votes


















0














this script is get data from server under a service display as a combobox options



services.php



<?php

//i'm using array u can use mysql array
$services=array();
$services=array('name'=>'Flowers');
$services=array('name'=>'Fruits');

//data under services
$data=array();
$data['Flowers']=array('Rose','Belly');
$data['Fruits']=array('Banana','Mango');

//check the the client is requested for data under a service
if(isset($_GET['get_data'])){
$current_service=$_GET['get_data'];
$data_array=$data[$current_service];
echo '<option selected="">Select</option>';
foreach($data_array as $op){
echo '<option value="'.$op.'">'.$op.'</option>';
}
}else{
?>
<fieldset>
<div class="form-group">
<select class="custom-select" name="Services" id="Services" onchange="Getnext_option(this.value)">
<option selected="">Select</option>
<?php foreach ($services as $item): ?>
<option value="<?php echo $item['name']; ?>"><?php echo $item['name']; ?></option> <?php endforeach;?>
</select>
</div>
</fieldset>

<fieldset>
<div class="form-group">
<select class="custom-select" name="Loaded_data" id="Loaded_data" style="display: none"> </select>
</div>
</fieldset>

<script>function Getnext_option(id){
var load_to=document.getElementById('Loaded_data');
load_to.style.display="none";
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
load_to.innerHTML=
this.responseText;
load_to.style.display="block";
}
};
xhttp.open("GET","services.php?get_data="+id, true);//get data from server
xhttp.send();
}</script>

<?php } ?>





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430080%2fcombobox-based-on-another-combobox%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    this script is get data from server under a service display as a combobox options



    services.php



    <?php

    //i'm using array u can use mysql array
    $services=array();
    $services=array('name'=>'Flowers');
    $services=array('name'=>'Fruits');

    //data under services
    $data=array();
    $data['Flowers']=array('Rose','Belly');
    $data['Fruits']=array('Banana','Mango');

    //check the the client is requested for data under a service
    if(isset($_GET['get_data'])){
    $current_service=$_GET['get_data'];
    $data_array=$data[$current_service];
    echo '<option selected="">Select</option>';
    foreach($data_array as $op){
    echo '<option value="'.$op.'">'.$op.'</option>';
    }
    }else{
    ?>
    <fieldset>
    <div class="form-group">
    <select class="custom-select" name="Services" id="Services" onchange="Getnext_option(this.value)">
    <option selected="">Select</option>
    <?php foreach ($services as $item): ?>
    <option value="<?php echo $item['name']; ?>"><?php echo $item['name']; ?></option> <?php endforeach;?>
    </select>
    </div>
    </fieldset>

    <fieldset>
    <div class="form-group">
    <select class="custom-select" name="Loaded_data" id="Loaded_data" style="display: none"> </select>
    </div>
    </fieldset>

    <script>function Getnext_option(id){
    var load_to=document.getElementById('Loaded_data');
    load_to.style.display="none";
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
    load_to.innerHTML=
    this.responseText;
    load_to.style.display="block";
    }
    };
    xhttp.open("GET","services.php?get_data="+id, true);//get data from server
    xhttp.send();
    }</script>

    <?php } ?>





    share|improve this answer




























      0














      this script is get data from server under a service display as a combobox options



      services.php



      <?php

      //i'm using array u can use mysql array
      $services=array();
      $services=array('name'=>'Flowers');
      $services=array('name'=>'Fruits');

      //data under services
      $data=array();
      $data['Flowers']=array('Rose','Belly');
      $data['Fruits']=array('Banana','Mango');

      //check the the client is requested for data under a service
      if(isset($_GET['get_data'])){
      $current_service=$_GET['get_data'];
      $data_array=$data[$current_service];
      echo '<option selected="">Select</option>';
      foreach($data_array as $op){
      echo '<option value="'.$op.'">'.$op.'</option>';
      }
      }else{
      ?>
      <fieldset>
      <div class="form-group">
      <select class="custom-select" name="Services" id="Services" onchange="Getnext_option(this.value)">
      <option selected="">Select</option>
      <?php foreach ($services as $item): ?>
      <option value="<?php echo $item['name']; ?>"><?php echo $item['name']; ?></option> <?php endforeach;?>
      </select>
      </div>
      </fieldset>

      <fieldset>
      <div class="form-group">
      <select class="custom-select" name="Loaded_data" id="Loaded_data" style="display: none"> </select>
      </div>
      </fieldset>

      <script>function Getnext_option(id){
      var load_to=document.getElementById('Loaded_data');
      load_to.style.display="none";
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
      load_to.innerHTML=
      this.responseText;
      load_to.style.display="block";
      }
      };
      xhttp.open("GET","services.php?get_data="+id, true);//get data from server
      xhttp.send();
      }</script>

      <?php } ?>





      share|improve this answer


























        0












        0








        0







        this script is get data from server under a service display as a combobox options



        services.php



        <?php

        //i'm using array u can use mysql array
        $services=array();
        $services=array('name'=>'Flowers');
        $services=array('name'=>'Fruits');

        //data under services
        $data=array();
        $data['Flowers']=array('Rose','Belly');
        $data['Fruits']=array('Banana','Mango');

        //check the the client is requested for data under a service
        if(isset($_GET['get_data'])){
        $current_service=$_GET['get_data'];
        $data_array=$data[$current_service];
        echo '<option selected="">Select</option>';
        foreach($data_array as $op){
        echo '<option value="'.$op.'">'.$op.'</option>';
        }
        }else{
        ?>
        <fieldset>
        <div class="form-group">
        <select class="custom-select" name="Services" id="Services" onchange="Getnext_option(this.value)">
        <option selected="">Select</option>
        <?php foreach ($services as $item): ?>
        <option value="<?php echo $item['name']; ?>"><?php echo $item['name']; ?></option> <?php endforeach;?>
        </select>
        </div>
        </fieldset>

        <fieldset>
        <div class="form-group">
        <select class="custom-select" name="Loaded_data" id="Loaded_data" style="display: none"> </select>
        </div>
        </fieldset>

        <script>function Getnext_option(id){
        var load_to=document.getElementById('Loaded_data');
        load_to.style.display="none";
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
        load_to.innerHTML=
        this.responseText;
        load_to.style.display="block";
        }
        };
        xhttp.open("GET","services.php?get_data="+id, true);//get data from server
        xhttp.send();
        }</script>

        <?php } ?>





        share|improve this answer













        this script is get data from server under a service display as a combobox options



        services.php



        <?php

        //i'm using array u can use mysql array
        $services=array();
        $services=array('name'=>'Flowers');
        $services=array('name'=>'Fruits');

        //data under services
        $data=array();
        $data['Flowers']=array('Rose','Belly');
        $data['Fruits']=array('Banana','Mango');

        //check the the client is requested for data under a service
        if(isset($_GET['get_data'])){
        $current_service=$_GET['get_data'];
        $data_array=$data[$current_service];
        echo '<option selected="">Select</option>';
        foreach($data_array as $op){
        echo '<option value="'.$op.'">'.$op.'</option>';
        }
        }else{
        ?>
        <fieldset>
        <div class="form-group">
        <select class="custom-select" name="Services" id="Services" onchange="Getnext_option(this.value)">
        <option selected="">Select</option>
        <?php foreach ($services as $item): ?>
        <option value="<?php echo $item['name']; ?>"><?php echo $item['name']; ?></option> <?php endforeach;?>
        </select>
        </div>
        </fieldset>

        <fieldset>
        <div class="form-group">
        <select class="custom-select" name="Loaded_data" id="Loaded_data" style="display: none"> </select>
        </div>
        </fieldset>

        <script>function Getnext_option(id){
        var load_to=document.getElementById('Loaded_data');
        load_to.style.display="none";
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
        load_to.innerHTML=
        this.responseText;
        load_to.style.display="block";
        }
        };
        xhttp.open("GET","services.php?get_data="+id, true);//get data from server
        xhttp.send();
        }</script>

        <?php } ?>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 12:10









        Mahfuzar RahmanMahfuzar Rahman

        14919




        14919






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430080%2fcombobox-based-on-another-combobox%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            Refactoring coordinates for Minecraft Pi buildings written in Python