• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fill textboxes after record selected by drop down

#1
[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

#2
[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.

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

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

#4
[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

#5
[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!

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.