Welcome Guest, Not a member yet? Register   Sign In
[Help] with <select> auto reload
#1

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

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

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

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

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

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

#7

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

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB