├── .gitignore ├── LICENSE ├── README.md ├── README.txt ├── application ├── .htaccess ├── config │ ├── autoload.php │ ├── config.php │ ├── constants.php │ ├── database.php │ ├── doctypes.php │ ├── foreign_chars.php │ ├── hooks.php │ ├── index.html │ ├── migration.php │ ├── mimes.php │ ├── profiler.php │ ├── routes.php │ ├── smileys.php │ └── user_agents.php ├── controllers │ ├── dropdown.php │ └── index.html ├── core │ └── index.html ├── errors │ ├── error_404.php │ ├── error_db.php │ ├── error_general.php │ ├── error_php.php │ └── index.html ├── helpers │ └── index.html ├── hooks │ └── index.html ├── index.html ├── language │ └── english │ │ └── index.html ├── libraries │ └── index.html ├── logs │ └── index.html ├── models │ ├── dropdown_model.php │ └── index.html ├── third_party │ └── index.html └── views │ ├── dropdown │ └── index.php │ ├── html │ ├── footer.php │ └── header.php │ └── index.html ├── cidropdown.sql ├── css ├── bootstrap.min.css └── styles.css ├── index.php ├── js └── dropdown.js ├── license.txt └── system ├── .htaccess ├── core ├── Benchmark.php ├── CodeIgniter.php ├── Common.php ├── Config.php ├── Controller.php ├── Exceptions.php ├── Hooks.php ├── Input.php ├── Lang.php ├── Loader.php ├── Model.php ├── Output.php ├── Router.php ├── Security.php ├── URI.php ├── Utf8.php └── index.html ├── database ├── DB.php ├── DB_active_rec.php ├── DB_cache.php ├── DB_driver.php ├── DB_forge.php ├── DB_result.php ├── DB_utility.php ├── drivers │ ├── cubrid │ │ ├── cubrid_driver.php │ │ ├── cubrid_forge.php │ │ ├── cubrid_result.php │ │ ├── cubrid_utility.php │ │ └── index.html │ ├── index.html │ ├── mssql │ │ ├── index.html │ │ ├── mssql_driver.php │ │ ├── mssql_forge.php │ │ ├── mssql_result.php │ │ └── mssql_utility.php │ ├── mysql │ │ ├── index.html │ │ ├── mysql_driver.php │ │ ├── mysql_forge.php │ │ ├── mysql_result.php │ │ └── mysql_utility.php │ ├── mysqli │ │ ├── index.html │ │ ├── mysqli_driver.php │ │ ├── mysqli_forge.php │ │ ├── mysqli_result.php │ │ └── mysqli_utility.php │ ├── oci8 │ │ ├── index.html │ │ ├── oci8_driver.php │ │ ├── oci8_forge.php │ │ ├── oci8_result.php │ │ └── oci8_utility.php │ ├── odbc │ │ ├── index.html │ │ ├── odbc_driver.php │ │ ├── odbc_forge.php │ │ ├── odbc_result.php │ │ └── odbc_utility.php │ ├── pdo │ │ ├── index.html │ │ ├── pdo_driver.php │ │ ├── pdo_forge.php │ │ ├── pdo_result.php │ │ └── pdo_utility.php │ ├── postgre │ │ ├── index.html │ │ ├── postgre_driver.php │ │ ├── postgre_forge.php │ │ ├── postgre_result.php │ │ └── postgre_utility.php │ ├── sqlite │ │ ├── index.html │ │ ├── sqlite_driver.php │ │ ├── sqlite_forge.php │ │ ├── sqlite_result.php │ │ └── sqlite_utility.php │ └── sqlsrv │ │ ├── index.html │ │ ├── sqlsrv_driver.php │ │ ├── sqlsrv_forge.php │ │ ├── sqlsrv_result.php │ │ └── sqlsrv_utility.php └── index.html ├── fonts ├── index.html └── texb.ttf ├── helpers ├── array_helper.php ├── captcha_helper.php ├── cookie_helper.php ├── date_helper.php ├── directory_helper.php ├── download_helper.php ├── email_helper.php ├── file_helper.php ├── form_helper.php ├── html_helper.php ├── index.html ├── inflector_helper.php ├── language_helper.php ├── number_helper.php ├── path_helper.php ├── security_helper.php ├── smiley_helper.php ├── string_helper.php ├── text_helper.php ├── typography_helper.php ├── url_helper.php └── xml_helper.php ├── index.html ├── language ├── english │ ├── calendar_lang.php │ ├── date_lang.php │ ├── db_lang.php │ ├── email_lang.php │ ├── form_validation_lang.php │ ├── ftp_lang.php │ ├── imglib_lang.php │ ├── index.html │ ├── migration_lang.php │ ├── number_lang.php │ ├── profiler_lang.php │ ├── unit_test_lang.php │ └── upload_lang.php └── index.html └── libraries ├── Cache ├── Cache.php └── drivers │ ├── Cache_apc.php │ ├── Cache_dummy.php │ ├── Cache_file.php │ └── Cache_memcached.php ├── Calendar.php ├── Cart.php ├── Driver.php ├── Email.php ├── Encrypt.php ├── Form_validation.php ├── Ftp.php ├── Image_lib.php ├── Javascript.php ├── Log.php ├── Migration.php ├── Pagination.php ├── Parser.php ├── Profiler.php ├── Session.php ├── Sha1.php ├── Table.php ├── Trackback.php ├── Typography.php ├── Unit_test.php ├── Upload.php ├── User_agent.php ├── Xmlrpc.php ├── Xmlrpcs.php ├── Zip.php ├── index.html └── javascript └── Jquery.php /.gitignore: -------------------------------------------------------------------------------- 1 | */config/development 2 | */logs/log-*.php 3 | */logs/!index.html 4 | */cache/* 5 | */cache/!index.html 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/theninthnode/codeigniter-ajax-dropdown/c59a6218f898b1389bf3b6d66277f52fa8658b81/LICENSE -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | codeigniter-ajax-dropdown 2 | ========================= 3 | 4 | Example on how to manage category/subcategory select boxes with CI and jQuery 5 | 6 | MySQL DB file in cidropdown.sql. More details in readme.txt -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | README.txt 2 | 3 | This download contains all the files necessary to get a complete working CodeIgniter application that contain a dropdown ajax filtering feature. 4 | 5 | Important files: 6 | 7 | - application > controllers > dropdown.php 8 | This is the default controller that loads the dropdown model and view files and contains method for getting sub options 9 | 10 | - application > models > dropdown_model.php 11 | This is the dropdown model that interacts with the database for pulling options and suboptions 12 | 13 | - application > view > dropdown > index.php 14 | This is the main view that contains the dropdown controls (selects) 15 | 16 | - application > view > html > header.php 17 | Pulled into main view and loads all CSS and JS including CDN version of jQuery 18 | 19 | - js > dropdown.js 20 | This is the main javascript file that performs the Ajax functions and loads JSON values into the select controls 21 | 22 | - cidropdown.sql 23 | SQL file that will create and populate two tables, options and suboptions. 24 | 25 | Credits: 26 | 27 | - Bootsrap CSS by twitter http://twitter.github.com/bootstrap/ 28 | - jQuery - http://jquery.com/ -------------------------------------------------------------------------------- /application/.htaccess: -------------------------------------------------------------------------------- 1 | Deny from all -------------------------------------------------------------------------------- /application/config/autoload.php: -------------------------------------------------------------------------------- 1 | '', 5 | 'xhtml1-strict' => '', 6 | 'xhtml1-trans' => '', 7 | 'xhtml1-frame' => '', 8 | 'html5' => '', 9 | 'html4-strict' => '', 10 | 'html4-trans' => '', 11 | 'html4-frame' => '' 12 | ); 13 | 14 | /* End of file doctypes.php */ 15 | /* Location: ./application/config/doctypes.php */ -------------------------------------------------------------------------------- /application/config/foreign_chars.php: -------------------------------------------------------------------------------- 1 | 'ae', 12 | '/ö|œ/' => 'oe', 13 | '/ü/' => 'ue', 14 | '/Ä/' => 'Ae', 15 | '/Ü/' => 'Ue', 16 | '/Ö/' => 'Oe', 17 | '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ/' => 'A', 18 | '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª/' => 'a', 19 | '/Ç|Ć|Ĉ|Ċ|Č/' => 'C', 20 | '/ç|ć|ĉ|ċ|č/' => 'c', 21 | '/Ð|Ď|Đ/' => 'D', 22 | '/ð|ď|đ/' => 'd', 23 | '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě/' => 'E', 24 | '/è|é|ê|ë|ē|ĕ|ė|ę|ě/' => 'e', 25 | '/Ĝ|Ğ|Ġ|Ģ/' => 'G', 26 | '/ĝ|ğ|ġ|ģ/' => 'g', 27 | '/Ĥ|Ħ/' => 'H', 28 | '/ĥ|ħ/' => 'h', 29 | '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ/' => 'I', 30 | '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı/' => 'i', 31 | '/Ĵ/' => 'J', 32 | '/ĵ/' => 'j', 33 | '/Ķ/' => 'K', 34 | '/ķ/' => 'k', 35 | '/Ĺ|Ļ|Ľ|Ŀ|Ł/' => 'L', 36 | '/ĺ|ļ|ľ|ŀ|ł/' => 'l', 37 | '/Ñ|Ń|Ņ|Ň/' => 'N', 38 | '/ñ|ń|ņ|ň|ʼn/' => 'n', 39 | '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ/' => 'O', 40 | '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º/' => 'o', 41 | '/Ŕ|Ŗ|Ř/' => 'R', 42 | '/ŕ|ŗ|ř/' => 'r', 43 | '/Ś|Ŝ|Ş|Š/' => 'S', 44 | '/ś|ŝ|ş|š|ſ/' => 's', 45 | '/Ţ|Ť|Ŧ/' => 'T', 46 | '/ţ|ť|ŧ/' => 't', 47 | '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ/' => 'U', 48 | '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ/' => 'u', 49 | '/Ý|Ÿ|Ŷ/' => 'Y', 50 | '/ý|ÿ|ŷ/' => 'y', 51 | '/Ŵ/' => 'W', 52 | '/ŵ/' => 'w', 53 | '/Ź|Ż|Ž/' => 'Z', 54 | '/ź|ż|ž/' => 'z', 55 | '/Æ|Ǽ/' => 'AE', 56 | '/ß/'=> 'ss', 57 | '/IJ/' => 'IJ', 58 | '/ij/' => 'ij', 59 | '/Œ/' => 'OE', 60 | '/ƒ/' => 'f' 61 | ); 62 | 63 | /* End of file foreign_chars.php */ 64 | /* Location: ./application/config/foreign_chars.php */ -------------------------------------------------------------------------------- /application/config/hooks.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /application/config/migration.php: -------------------------------------------------------------------------------- 1 | migration->latest() this is the version that schema will 21 | | be upgraded / downgraded to. 22 | | 23 | */ 24 | $config['migration_version'] = 0; 25 | 26 | 27 | /* 28 | |-------------------------------------------------------------------------- 29 | | Migrations Path 30 | |-------------------------------------------------------------------------- 31 | | 32 | | Path to your migrations folder. 33 | | Typically, it will be within your application path. 34 | | Also, writing permission is required within the migrations path. 35 | | 36 | */ 37 | $config['migration_path'] = APPPATH . 'migrations/'; 38 | 39 | 40 | /* End of file migration.php */ 41 | /* Location: ./application/config/migration.php */ -------------------------------------------------------------------------------- /application/config/mimes.php: -------------------------------------------------------------------------------- 1 | 'application/mac-binhex40', 12 | 'cpt' => 'application/mac-compactpro', 13 | 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'), 14 | 'bin' => 'application/macbinary', 15 | 'dms' => 'application/octet-stream', 16 | 'lha' => 'application/octet-stream', 17 | 'lzh' => 'application/octet-stream', 18 | 'exe' => array('application/octet-stream', 'application/x-msdownload'), 19 | 'class' => 'application/octet-stream', 20 | 'psd' => 'application/x-photoshop', 21 | 'so' => 'application/octet-stream', 22 | 'sea' => 'application/octet-stream', 23 | 'dll' => 'application/octet-stream', 24 | 'oda' => 'application/oda', 25 | 'pdf' => array('application/pdf', 'application/x-download'), 26 | 'ai' => 'application/postscript', 27 | 'eps' => 'application/postscript', 28 | 'ps' => 'application/postscript', 29 | 'smi' => 'application/smil', 30 | 'smil' => 'application/smil', 31 | 'mif' => 'application/vnd.mif', 32 | 'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'), 33 | 'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'), 34 | 'wbxml' => 'application/wbxml', 35 | 'wmlc' => 'application/wmlc', 36 | 'dcr' => 'application/x-director', 37 | 'dir' => 'application/x-director', 38 | 'dxr' => 'application/x-director', 39 | 'dvi' => 'application/x-dvi', 40 | 'gtar' => 'application/x-gtar', 41 | 'gz' => 'application/x-gzip', 42 | 'php' => 'application/x-httpd-php', 43 | 'php4' => 'application/x-httpd-php', 44 | 'php3' => 'application/x-httpd-php', 45 | 'phtml' => 'application/x-httpd-php', 46 | 'phps' => 'application/x-httpd-php-source', 47 | 'js' => 'application/x-javascript', 48 | 'swf' => 'application/x-shockwave-flash', 49 | 'sit' => 'application/x-stuffit', 50 | 'tar' => 'application/x-tar', 51 | 'tgz' => array('application/x-tar', 'application/x-gzip-compressed'), 52 | 'xhtml' => 'application/xhtml+xml', 53 | 'xht' => 'application/xhtml+xml', 54 | 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'), 55 | 'mid' => 'audio/midi', 56 | 'midi' => 'audio/midi', 57 | 'mpga' => 'audio/mpeg', 58 | 'mp2' => 'audio/mpeg', 59 | 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'), 60 | 'aif' => 'audio/x-aiff', 61 | 'aiff' => 'audio/x-aiff', 62 | 'aifc' => 'audio/x-aiff', 63 | 'ram' => 'audio/x-pn-realaudio', 64 | 'rm' => 'audio/x-pn-realaudio', 65 | 'rpm' => 'audio/x-pn-realaudio-plugin', 66 | 'ra' => 'audio/x-realaudio', 67 | 'rv' => 'video/vnd.rn-realvideo', 68 | 'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'), 69 | 'bmp' => array('image/bmp', 'image/x-windows-bmp'), 70 | 'gif' => 'image/gif', 71 | 'jpeg' => array('image/jpeg', 'image/pjpeg'), 72 | 'jpg' => array('image/jpeg', 'image/pjpeg'), 73 | 'jpe' => array('image/jpeg', 'image/pjpeg'), 74 | 'png' => array('image/png', 'image/x-png'), 75 | 'tiff' => 'image/tiff', 76 | 'tif' => 'image/tiff', 77 | 'css' => 'text/css', 78 | 'html' => 'text/html', 79 | 'htm' => 'text/html', 80 | 'shtml' => 'text/html', 81 | 'txt' => 'text/plain', 82 | 'text' => 'text/plain', 83 | 'log' => array('text/plain', 'text/x-log'), 84 | 'rtx' => 'text/richtext', 85 | 'rtf' => 'text/rtf', 86 | 'xml' => 'text/xml', 87 | 'xsl' => 'text/xml', 88 | 'mpeg' => 'video/mpeg', 89 | 'mpg' => 'video/mpeg', 90 | 'mpe' => 'video/mpeg', 91 | 'qt' => 'video/quicktime', 92 | 'mov' => 'video/quicktime', 93 | 'avi' => 'video/x-msvideo', 94 | 'movie' => 'video/x-sgi-movie', 95 | 'doc' => 'application/msword', 96 | 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 97 | 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 98 | 'word' => array('application/msword', 'application/octet-stream'), 99 | 'xl' => 'application/excel', 100 | 'eml' => 'message/rfc822', 101 | 'json' => array('application/json', 'text/json') 102 | ); 103 | 104 | 105 | /* End of file mimes.php */ 106 | /* Location: ./application/config/mimes.php */ 107 | -------------------------------------------------------------------------------- /application/config/profiler.php: -------------------------------------------------------------------------------- 1 | array('grin.gif', '19', '19', 'grin'), 20 | ':lol:' => array('lol.gif', '19', '19', 'LOL'), 21 | ':cheese:' => array('cheese.gif', '19', '19', 'cheese'), 22 | ':)' => array('smile.gif', '19', '19', 'smile'), 23 | ';-)' => array('wink.gif', '19', '19', 'wink'), 24 | ';)' => array('wink.gif', '19', '19', 'wink'), 25 | ':smirk:' => array('smirk.gif', '19', '19', 'smirk'), 26 | ':roll:' => array('rolleyes.gif', '19', '19', 'rolleyes'), 27 | ':-S' => array('confused.gif', '19', '19', 'confused'), 28 | ':wow:' => array('surprise.gif', '19', '19', 'surprised'), 29 | ':bug:' => array('bigsurprise.gif', '19', '19', 'big surprise'), 30 | ':-P' => array('tongue_laugh.gif', '19', '19', 'tongue laugh'), 31 | '%-P' => array('tongue_rolleye.gif', '19', '19', 'tongue rolleye'), 32 | ';-P' => array('tongue_wink.gif', '19', '19', 'tongue wink'), 33 | ':P' => array('raspberry.gif', '19', '19', 'raspberry'), 34 | ':blank:' => array('blank.gif', '19', '19', 'blank stare'), 35 | ':long:' => array('longface.gif', '19', '19', 'long face'), 36 | ':ohh:' => array('ohh.gif', '19', '19', 'ohh'), 37 | ':grrr:' => array('grrr.gif', '19', '19', 'grrr'), 38 | ':gulp:' => array('gulp.gif', '19', '19', 'gulp'), 39 | '8-/' => array('ohoh.gif', '19', '19', 'oh oh'), 40 | ':down:' => array('downer.gif', '19', '19', 'downer'), 41 | ':red:' => array('embarrassed.gif', '19', '19', 'red face'), 42 | ':sick:' => array('sick.gif', '19', '19', 'sick'), 43 | ':shut:' => array('shuteye.gif', '19', '19', 'shut eye'), 44 | ':-/' => array('hmm.gif', '19', '19', 'hmmm'), 45 | '>:(' => array('mad.gif', '19', '19', 'mad'), 46 | ':mad:' => array('mad.gif', '19', '19', 'mad'), 47 | '>:-(' => array('angry.gif', '19', '19', 'angry'), 48 | ':angry:' => array('angry.gif', '19', '19', 'angry'), 49 | ':zip:' => array('zip.gif', '19', '19', 'zipper'), 50 | ':kiss:' => array('kiss.gif', '19', '19', 'kiss'), 51 | ':ahhh:' => array('shock.gif', '19', '19', 'shock'), 52 | ':coolsmile:' => array('shade_smile.gif', '19', '19', 'cool smile'), 53 | ':coolsmirk:' => array('shade_smirk.gif', '19', '19', 'cool smirk'), 54 | ':coolgrin:' => array('shade_grin.gif', '19', '19', 'cool grin'), 55 | ':coolhmm:' => array('shade_hmm.gif', '19', '19', 'cool hmm'), 56 | ':coolmad:' => array('shade_mad.gif', '19', '19', 'cool mad'), 57 | ':coolcheese:' => array('shade_cheese.gif', '19', '19', 'cool cheese'), 58 | ':vampire:' => array('vampire.gif', '19', '19', 'vampire'), 59 | ':snake:' => array('snake.gif', '19', '19', 'snake'), 60 | ':exclaim:' => array('exclaim.gif', '19', '19', 'excaim'), 61 | ':question:' => array('question.gif', '19', '19', 'question') // no comma after last item 62 | 63 | ); 64 | 65 | /* End of file smileys.php */ 66 | /* Location: ./application/config/smileys.php */ -------------------------------------------------------------------------------- /application/controllers/dropdown.php: -------------------------------------------------------------------------------- 1 | load->model('dropdown_model'); 6 | } 7 | 8 | function index(){ 9 | $data['options'] = $this->dropdown_model->getOptions(); 10 | $this->load->view('dropdown/index', $data); 11 | } 12 | 13 | function getsuboptions($option_id){ 14 | $this->dropdown_model->option_id = $option_id; 15 | $suboptions = $this->dropdown_model->getSubOptions(); 16 | 17 | header('Content-Type: application/x-json; charset=utf-8'); 18 | echo json_encode($suboptions); 19 | } 20 | } -------------------------------------------------------------------------------- /application/controllers/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /application/core/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /application/errors/error_404.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 404 Page Not Found 5 | 55 | 56 | 57 |
58 |

59 | 60 |
61 | 62 | -------------------------------------------------------------------------------- /application/errors/error_db.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Database Error 5 | 55 | 56 | 57 |
58 |

59 | 60 |
61 | 62 | -------------------------------------------------------------------------------- /application/errors/error_general.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Error 5 | 55 | 56 | 57 |
58 |

59 | 60 |
61 | 62 | -------------------------------------------------------------------------------- /application/errors/error_php.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |

A PHP Error was encountered

4 | 5 |

Severity:

6 |

Message:

7 |

Filename:

8 |

Line Number:

9 | 10 |
-------------------------------------------------------------------------------- /application/errors/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /application/helpers/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /application/hooks/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /application/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /application/language/english/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /application/libraries/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /application/logs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /application/models/dropdown_model.php: -------------------------------------------------------------------------------- 1 | db->select('id, value') 19 | ->get('options')->result(); 20 | 21 | $options_arr; 22 | 23 | $options_arr['#'] = '-- Please Select Option --'; 24 | 25 | // Format for passing into form_dropdown function 26 | 27 | foreach ($options as $option) { 28 | $options_arr[$option->id] = $option->value; 29 | } 30 | 31 | return $options_arr; 32 | } 33 | 34 | /** 35 | * 36 | * Gets sub options 37 | * returns array 38 | * 39 | **/ 40 | function getSubOptions(){ 41 | if(!is_null($this->option_id)){ 42 | $this->db->select('id, value'); 43 | $this->db->where('option_id', $this->option_id); 44 | $suboptions = $this->db->get('suboptions'); 45 | 46 | // if there are suboptinos for this option... 47 | if($suboptions->num_rows() > 0){ 48 | $suboptions_arr; 49 | 50 | // Format for passing into jQuery loop 51 | 52 | foreach ($suboptions->result() as $suboption) { 53 | $suboptions_arr[$suboption->id] = $suboption->value; 54 | } 55 | 56 | return $suboptions_arr; 57 | } 58 | } 59 | 60 | return; 61 | } 62 | } 63 | ?> -------------------------------------------------------------------------------- /application/models/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /application/third_party/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /application/views/dropdown/index.php: -------------------------------------------------------------------------------- 1 | load->view('html/header');?> 2 |

CodeIgniter Ajax Dropdown

3 |

Select an option to get a list of suboptions. 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | load->view('html/footer');?> -------------------------------------------------------------------------------- /application/views/html/footer.php: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /application/views/html/header.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeIgniter Ajax Dropdown 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /application/views/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /cidropdown.sql: -------------------------------------------------------------------------------- 1 | SET NAMES utf8; 2 | SET FOREIGN_KEY_CHECKS = 0; 3 | 4 | -- ---------------------------- 5 | -- Table structure for `options` 6 | -- ---------------------------- 7 | DROP TABLE IF EXISTS `options`; 8 | CREATE TABLE `options` ( 9 | `id` int(11) NOT NULL AUTO_INCREMENT, 10 | `value` varchar(255) NOT NULL, 11 | PRIMARY KEY (`id`) 12 | ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; 13 | 14 | -- ---------------------------- 15 | -- Records of `options` 16 | -- ---------------------------- 17 | BEGIN; 18 | INSERT INTO `options` VALUES ('1', 'Option 1'), ('2', 'Option 2'), ('3', 'Option 3'), ('4', 'Option 4'); 19 | COMMIT; 20 | 21 | -- ---------------------------- 22 | -- Table structure for `suboptions` 23 | -- ---------------------------- 24 | DROP TABLE IF EXISTS `suboptions`; 25 | CREATE TABLE `suboptions` ( 26 | `id` int(11) NOT NULL AUTO_INCREMENT, 27 | `value` varchar(255) NOT NULL, 28 | `option_id` int(11) NOT NULL, 29 | PRIMARY KEY (`id`) 30 | ) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=latin1; 31 | 32 | -- ---------------------------- 33 | -- Records of `suboptions` 34 | -- ---------------------------- 35 | BEGIN; 36 | INSERT INTO `suboptions` VALUES ('1', 'Sub-option 1 for option 1', '1'), ('2', 'Sub-option 1 for option 2', '2'), ('3', 'Sub-option 2 for option 2', '2'), ('4', 'Sub-option 1 for option 3', '3'), ('5', 'Sub-option 2 for option 3', '3'), ('7', 'Sub-option 2 for option 1', '1'); 37 | COMMIT; 38 | 39 | SET FOREIGN_KEY_CHECKS = 1; 40 | -------------------------------------------------------------------------------- /css/styles.css: -------------------------------------------------------------------------------- 1 | body {padding: 20px 40px;} 2 | table {width:50% !important;} -------------------------------------------------------------------------------- /js/dropdown.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | $('#options').change(function(){ //any select change on the dropdown with id options trigger this code 3 | $("#suboptions > option").remove(); //first of all clear select items 4 | var option = $('#options').val(); // here we are taking option id of the selected one. 5 | 6 | if(option == '#'){ 7 | return false; // return false after clearing sub options if 'please select was chosen' 8 | } 9 | 10 | $.ajax({ 11 | type: "POST", 12 | url: "/dropdown/getsuboptions/"+option, //here we are calling our dropdown controller and getsuboptions method passing the option 13 | 14 | success: function(suboptions) //we're calling the response json array 'suboptions' 15 | { 16 | $.each(suboptions,function(id,value) //here we're doing a foeach loop round each sub option with id as the key and value as the value 17 | { 18 | var opt = $('