CodeIgniter Forums
Fill textboxes after record selected by drop down - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Fill textboxes after record selected by drop down (/thread-61069.html)



Fill textboxes after record selected by drop down - El Forum - 09-11-2014

[eluser]webmarkcompt[/eluser]
How can I add to this dropdown some textboxes that will appear with information about the selected record?



Code:
<div class="control-group">
    <label class="control-label" id="customer_l">&lt;?php echo $this->lang->line("customer"); ?&gt;</label>
    <div class="controls">  &lt;?php
        $cu[""] = "";
        foreach ($customers as $customer) {
            if ($customer->company == "-" || !$customer->company) {
                $cu[$customer->id] = $customer->name . " (P)";
            } else {
                $cu[$customer->id] = $customer->company . " (C)";
            }
        }
        echo form_dropdown('customer', $cu, (isset($_POST['customer']) ? $_POST['customer'] : ""), 'id="customer_s"   data-placeholder="' . $this-&gt;lang-&gt;line("select") . ' ' . $this->lang->line("customer") . '" required="required" data-error="' . $this-&gt;lang-&gt;line("customer") . ' ' . $this->lang->line("is_required") . '"');
        ?&gt; </div>
</div>

Any sugestion?
Thank you


Fill textboxes after record selected by drop down - El Forum - 09-11-2014

[eluser]CroNiX[/eluser]
One way would be with javascript and ajax. When select value changes, use ajax to send request to server based on value of select, and then display the data the controller sends back in textboxes, divs, or whatever. If you've used jquery before, this should be pretty easy to do.

Another way would be to submit the form, and in the controller check the value of the dropdown post value, and get additional info based on that to redisplay in the view.


Fill textboxes after record selected by drop down - El Forum - 09-11-2014

[eluser]CroNiX[/eluser]
Also, in your dropdown, this:
Code:
(isset($_POST['customer']) ? $_POST['customer'] : "")

can be replaced with
Code:
set_value('customer')



Fill textboxes after record selected by drop down - El Forum - 09-11-2014

[eluser]webmarkcompt[/eluser]
[quote author="CroNiX" date="1410463374"]Also, in your dropdown, this:
Code:
(isset($_POST['customer']) ? $_POST['customer'] : "")

can be replaced with
Code:
set_value('customer')
[/quote]

Thank you.

I will try to this with jQuery



Fill textboxes after record selected by drop down - El Forum - 09-15-2014

[eluser]webmarkcompt[/eluser]
Code:
[removed][removed]

[removed]
$(document).ready(function(){
$('#leather_description').hide();
$("#leather").change(function(){
$('#leather_description').hide('slow');
$("#" + this.value).show('slow');
});
});
[removed]

&lt;!-- ADICIONAR LEATHER--&gt;
<div class="control-group">
  <label class="control-label" id="leather">&lt;?php echo $this->lang->line("trad_leather"); ?&gt;</label>
  <div class="controls">  &lt;?php
   $leath[""] = "";
      foreach($tbl_leather as $sort){
    $leath[$sort->id] = $sort->description;
   }
  echo form_dropdown('leather', $leath,  set_value('leather'), 'id="leather" data-placeholder="'.$this-&gt;lang-&gt;line("select").' '.$this->lang->line("trad_leather").'" required="required" data-error="'.$this-&gt;lang-&gt;line("trad_leather").' '.$this->lang->line("is_required").'"'); ?&gt; </div>
        
        <div id="leather_description"> &lt;input class="input-text" type="text" name="leather_description" placeholder="Leather Description"/&gt;&lt;/div>
</div>

Hello again

How can I define the value variable to show de div leather_description?
Can you give some hint to solve this issue?
Thank you!


Fill textboxes after record selected by drop down - El Forum - 09-15-2014

[eluser]adela[/eluser]
Please delete my post. I typed it by mistake. Thanks