Welcome Guest, Not a member yet? Register   Sign In
CI & jQuery Linked dropdowns
#1

[eluser]edwin87[/eluser]
Hello CI,

I was trying to add a jQuery linked dropdown script.

See here

In the example i was able to do some changes.

But now add it to CI.

I think it's wrong with the function that call's a url. This URL has without CI the script name. Like this:
Quote:select.php

So i think in CI it would be something like this :
Quote:base_ur()/system/application/classname/function/value

But there is no action at all.


Code:
$('#building').linkedSelect('<?php echo base_url();?>index.php/buildings/selectbox/building','#levels',{firstOption: 'Select a level'});
$('#levels').linkedSelect('<?php echo base_url();?>index.php/buildings/selectbox/levels','#rooms',{firstOption: 'Select a room'});
$('#rooms').linkedSelect('<?php echo base_url();?>index.php/buildings/selectbox/rooms','#segmenten',{firstOption: 'Select a rack segment', loadingText: 'Loading...'});

Can anyone help me with this?

Thnx
#2

[eluser]narkaT[/eluser]
according to your urls you have one controller named "buildings" containing
a method "selectbox" which gets passed 1 parameter right?

did you try opening these urls direkly via the browser?
or looked hat the xhr-requests with firebug?

maybe you misspelled something and CI cant find the controller/method.
#3

[eluser]edwin87[/eluser]
Okay i forgot a parameter what is really stupid.

Code:
$('#building').linkedSelect('<?php echo base_url();?>index.php/buildings/selectbox/building','#levels',{firstOption: 'Select a level'});

It has to be something like this:

Quote:classname/function/parameter1/parameter2

Parameter1 : Building
Paramater2 : Id to search.

But how can i fill parameter 2?


The example script with php was:

Code:
<?php

$json = array();

// Lets get the variables we passed
$search = isset($_GET['search']) ? (string) $_GET['search'] : '';

$str = isset($_GET['str']) ? (string) $_GET['str'] : '';

// Cleans query string before we run the selects below.
// Allows A-Z, a-z, 0-9, whitespace, minus/hyphen, equals, ampersand, underscore, and period/full stop.
$str = preg_replace("/[^A-Za-z0-9\s\-\=\&\_\.]/","", $str);

$str = mysql_real_escape_string($str);


switch ($search) {

   case "building":

      $sql = mysql_query("SELECT * FROM Levels WHERE BuildingPart_ID = '{$str}'");

      while ($rows = mysql_fetch_array($sql)) {

         $json[] = "{optionValue: ".$rows["Level_ID"].", optionDisplay: '".$rows["Name"]."'}";
      }

      echo '[' . implode(',', $json) . ']';

   break;

   case "levels":

      $sql = mysql_query("SELECT * FROM Rooms WHERE Level_ID = '{$str}'");

      while ($rows = mysql_fetch_array($sql)) {

         $json[] = '{"optionValue": "'.$rows["Room_ID"].'", "optionDisplay": "'.$rows["Name"].'"}';
      }

      echo '[' . implode(',', $json) . ']';

   break;

   case "rooms":

      $sql = mysql_query("SELECT * FROM Segmenten WHERE Room_ID = '{$str}'");

      while ($rows = mysql_fetch_array($sql)) {

         $json[] = '{"optionValue": "'.$rows["Segment_ID"].'", "optionDisplay": "'.$rows["Name"].'"}';
      }

      echo '[' . implode(',', $json) . ']';

   break;

   default:


      echo "Something has gone wrong!";


   break;

}
?>

You can see it want to use 2 get vars.
The first one i can fill.
But the second one does not work.
#4

[eluser]narkaT[/eluser]
get-parameters are not enabled by codeigniter by default.

but you could rewrite the JS-part of that script to user segment based urls Wink
#5

[eluser]hvalente13[/eluser]
Hi edwin87,

Did you get that working?

If so, can you share the code?




Theme © iAndrew 2016 - Forum software by © MyBB