[eluser]Unknown[/eluser]
hi i have the same problem with one of the member here. his screen name is theighost.
Here's the issue of theighost and my issue now as well:
"I am using codeigniter for a site and need to make a script that makes the following :
I have a dropdown list named “states” for example,and another drop down list named “cities”.
I want when i select a state the “cities” dropdown list to refresh automaticly,showing the cities in the state selected.
I saw many scripts on the net…but they were not for codeiginter and they were using the method get, which i dont really know how to apply it in codeigniter.
BTW the states and the cities are taken from a database and are not static info.
any help would be appreciated."
--------------------- My Code --------------------------------
MY CONTROLLER
$data['con_type'] = $this->db->query('SELECT type FROM contact_type');
MY VIEW PAGE
[removed]
function selType(Type)
{
var type = Type[Type.selectedIndex].value;
setList(type);
}
function callToSetList(data)
{
$('#list').html(data);
}
function setList(type)
{
$.post("ff.php", {ctype: type}, callToSetList);
}
[removed]
<select name="c_type">
<? foreach($con_type->result() as $row): ?>
<option><?=$row->type?></option>
<? endforeach; ?>
</select> <br /><br />
<select id="list" size="25" style="width:240px;">
<? foreach($list->result() as $row): ?>
<option><?=$row->name?></option>
<? endforeach; ?>
</select> <br />
FF.PHP page(I placed this outside system folder which is (base_url))
<?
mysql_connect("localhost", "root", "");
mysql_select_db("contacts");
$ctype = $_POST['ctype'];
$result = mysql_query("SELECT * FROM contacts WHERE type='$ctype'");
while($row = mysql_fetch_array($result))
{ ?>
<option value="<?=$row['name']?>"><?=$row['name']?></option>
<? } ?>
------------------------------------------------------------------
My problem with codeigniter is that we cannot post($_POST) anything in the view page just like in the normal PHP - in codeigniter which we can only do in the controller or model, so our only option would be to create a javascript.
anyone here who has a better algorithm for this issue?
thanks!