Welcome Guest, Not a member yet? Register   Sign In
ajax dropdown
#1

[eluser]ivahdam[/eluser]
Hello All


function stateDisplay(){
$data = '[removed]getStates();[removed])';
$this->db->where('country_code',$data);
$query = $this->db->get('states');
echo "<select name='state_code' id='state_code'>
<option value=''>Select State</option>";

foreach($query->result() as $row1) {
echo "<option value='".$row1->state_code."'> ".$row1->state_name."</option>";
} "</select>";
}

Here
query doesnot get executed........
getStates() is a javascript function which returns a country code
#2

[eluser]ggoforth[/eluser]
[quote author="ivahdam" date="1244544415"]Hello All


function stateDisplay(){
$data = '[removed]getStates();[removed])';
$this->db->where('country_code',$data);
$query = $this->db->get('states');
echo "<select name='state_code' id='state_code'>
<option value=''>Select State</option>";

foreach($query->result() as $row1) {
echo "<option value='".$row1->state_code."'> ".$row1->state_name."</option>";
} "</select>";
}

Here
query doesnot get executed........
getStates() is a javascript function which returns a country code[/quote]

I'm having a little trouble understanding how your trying to run getStates(). It looks like your trying to embed javascript inside a block of PHP. Is this the case? Unless I'm not understanding how your trying to run this function I would say your on the wrong track. If your already inside a block of PHP, just use a php function $this->getStates() (making sure getStates() lives in the same class).

I think we need to see more of your code. Out of context this looks odd to me.

Greg
#3

[eluser]ivahdam[/eluser]
yes getStates(); is a js function which returns a country code, and this is working fine
i.e. $data has country code.
if I edit my code as
function stateDisplay(){

$data = '[removed]getStates();[removed])';
query = $this->db->query("select * from states where country_code = '".$data."'");
echo $this->db->affected_rows();

echo "<select name='state_code' id='state_code'>
<option value=''>Select State</option>";

foreach($query->result() as $row1) {
echo "<option value='".$row1->state_code."'> ".$row1->state_name."</option>";
} "</select>";
}

It displays affected rows as 0, where an in database there are 2 records for that country code.
#4

[eluser]ggoforth[/eluser]
[quote author="ivahdam" date="1244546310"]yes getStates(); is a js function which returns a country code, and this is working fine
i.e. $data has country code.
if I edit my code as
function stateDisplay(){

$data = '[removed]getStates();[removed])';
query = $this->db->query("select * from states where country_code = '".$data."'");
echo $this->db->affected_rows();

echo "<select name='state_code' id='state_code'>
<option value=''>Select State</option>";

foreach($query->result() as $row1) {
echo "<option value='".$row1->state_code."'> ".$row1->state_name."</option>";
} "</select>";
}

It displays affected rows as 0, where an in database there are 2 records for that country code.[/quote]

What I am not understanding is how you are running a javascript function (client side) inside PHP (serverside). At the time you call stateDisplay() (which is PHP...right?) you wouldn't have access to the client side functions, IE getStates(). I don't understand the flow of how your calling the stateDisplay().

Am I missing something here? Anyone...?

Greg
#5

[eluser]ivahdam[/eluser]
actually i have a countries select box, on its onchange event i called a stateDisplay(), from here
i called a js function
[removed]getStates();[removed]
and it returns a country code which i have selected from my countries select box.
#6

[eluser]ggoforth[/eluser]
[quote author="ivahdam" date="1244547364"]actually i have a countries select box, on its onchange event i called a stateDisplay(), from here
i called a js function
[removed]getStates();[removed]
and it returns a country code which i have selected from my countries select box.[/quote]

Ok, so onchange of your select box your running an ajax call? If so, you can not call a javascript function inside the ajax call, because the select does not exist in the current state INSIDE the ajax call. The way you should do this is onchange of your select element run an ajax call and POST the information to your PHP script so instead of using javascript to select the value of an element, just use the passed in values.

I could be wrong, but I've never seen javascript inserted inside PHP the way your doing it. It just doesn't make any sense to me.

Greg
#7

[eluser]ivahdam[/eluser]
I will try your idea.
Thanks for responging.........
#8

[eluser]ggoforth[/eluser]
[quote author="ivahdam" date="1244548215"]I will try your idea.
Thanks for responging.........[/quote]

Sure, and if I'm misunderstanding something, please feel free to let me know. It just looks like your approaching it the wrong way. Hope you get it figured out!

Greg




Theme © iAndrew 2016 - Forum software by © MyBB