CodeIgniter Forums
[Help] with <select> auto reload - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [Help] with <select> auto reload (/showthread.php?tid=52976)

Pages: 1 2


[Help] with <select> auto reload - El Forum - 07-04-2012

[eluser]C_Line[/eluser]
i wan to register province and city

like this
//////////////////////////////////////////////////////////////////////////////////////
Code:
&lt;!--controller--&gt;
function daftar()
{
$this->load->view('header');
$this->load->view('frame_kiri');

$this->load->model('Query_barang','',TRUE);
$data['prop'] = $this->Query_barang->reg_prop();
$data['kota'] = $this->Query_barang->reg_kota();
$this->load->view('registrasi',$data);
}

&lt;!--model--&gt;
function reg_prop()
{
$prop = $this->db->query("select distinct(Propinsi) from tarif_kirim order by Propinsi ASC")->result();
return $prop;
}

function reg_kota()
{
$propi = $this->input->post('propinsi');
$kota = $this->db->query("select kota from tarif_kirim where Propinsi='$propi'")->result();
return $kot;
}

&lt;!--view--&gt;
<select name="propinsi" id="propinsi">
&lt;?php
foreach($prop as $kue)
{
?&gt;
<option value="&lt;?php echo $kue-&gt;Propinsi; ?&gt;">&lt;?php echo $kue->Propinsi; ?&gt;</option>
&lt;?php
}
?&gt;
</select>

Kota
<select name="kota_user">
&lt;?php
foreach($kota as $kues)
{
echo "<option value='". $kues-&gt;kota . "'>" . $kues->kota . "</option>";
}
?&gt;
</select>

[removed]
function come()
{
var el = document.getElementById('propinsi').value; // <- try to get value
document . write(el);
}
[removed]
//////////////////////////////////////////////////////////////////////////////////////

but it can't load, i dun wan use button
when i select propinsi, kota_user automatically load database and display it
help me,, thx



[Help] with <select> auto reload - El Forum - 07-04-2012

[eluser]marjune[/eluser]
the code above are in the views?


[Help] with <select> auto reload - El Forum - 07-04-2012

[eluser]C_Line[/eluser]
yea, this code in view


[Help] with <select> auto reload - El Forum - 07-04-2012

[eluser]marjune[/eluser]
well the propper of doing this code youre talking about is....

Controller
Code:
function functionanem(){
        
         $result['prop'] = $this->modelname->modelfinction("select distinct(Propinsi)
                                                            from tarif_kirim
                                                            order by Propinsi ASC");
         $this->load->view('yourview',$result);

  }

view
Code:
<select name=“propinsi” id=“propinsi”>
      &lt;?php foreach($prop as $kue){ ?&gt;
               <option value=”&lt;?php echo $kue->Propinsi; ?&gt;”>&lt;?php echo $kue->Propinsi; ?&gt;</option>
      &lt;?php }?&gt;
          
   </select>



[Help] with <select> auto reload - El Forum - 07-04-2012

[eluser]C_Line[/eluser]
yea, i'm too lazy to call function from model XD

but that didn't answer my question above T.T


[Help] with <select> auto reload - El Forum - 07-04-2012

[eluser]dnc[/eluser]
[quote author="C_Line" date="1341461651"]yea, i'm too lazy to call function from model XD

but that didn't answer my question above T.T[/quote]

First off, you will get better replies if you wrap your code in code tags.

Code:
I am a code

Secondly, your database query should not be in your view. It should be in a model or at the very least a controller.

No one is going to argue with you, or try to help you if you are "too lazy" to at least try to code correctly.




[Help] with <select> auto reload - El Forum - 07-04-2012

[eluser]C_Line[/eluser]
okay okay, i fix it Big Grin


[Help] with <select> auto reload - El Forum - 07-04-2012

[eluser]C_Line[/eluser]
i done revised Big Grin


[Help] with <select> auto reload - El Forum - 07-04-2012

[eluser]marjune[/eluser]
yes because the second select box which is kota depends from the first select box..
you're probably need a jquery to do it.



[Help] with <select> auto reload - El Forum - 07-05-2012

[eluser]C_Line[/eluser]
can't use ajax ? i dun know about jquery