Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 534433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:36:43+00:00 2026-05-13T09:36:43+00:00

I have the following controller and view. I am trying to learn jquery in

  • 0

I have the following controller and view. I am trying to learn jquery in codeigniter.

The code does not work. So I am hoping someone spot out what I am doing wrong and correct me.

Thanks in advance.

class PhpJqueryBook extends Controller
{

function __construct()
{
    parent::Controller(); }

public function index()
{
...    }

function dynamic_select_boxes(){

    $this->load->view('dynamic_select_boxes');

}

function get_cities(){

    switch(@$_POST['country']){
        case 'ie': // { ireland
            $cities=array('Cork', 'Dublin', 'Galway', 'Limerick',
              'Waterford');
        break;
        // }
        case 'uk': // { United Kingdom
            $cities=array('Bath', 'Birmingham', 'Bradford',
                'Brighton & Hove', 'Bristol',
                'Cambridge', 'Canterbury', 'Carlisle',
                'Chester', 'Chichester', 'Coventry',
                'Derby', 'Durham', 'Ely', 'Exeter',
                'Gloucester', 'Hereford', 'Kingston upon Hull',
                /* and on and on! */
                'Newport', 'St David\'s', 'Swansea');
        break;
        // }
        default: // { else
            $cities=false;
        // }
    }
    if(!$cities)echo 'please choose a country first';
    else echo '<select name="city"><option>'.join('</option>  <option>',$cities).'</select>';
}
}

views/dynamic_select_boxes.php

<?php $this->load->view('inc/header')?>

<form>
<table>
<tr><th>Country</th><td>
<select name="country" id="country">
<option value=""> -- please choose -- </option>
<option value="ie">Ireland</option>
<option value="uk">Great Britain</option>
</select>
</tr>
<tr>
<th>Cities</th>
<td id="cities">please choose a country first</td>
</tr>
</table>
<?php $this->load->view('inc/footer')?>

And this produces the following html.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <base href="http://127.0.0.1/ci_jquery/">
</head>
<body>

<form>
<table>
    <tr><th>Country</th><td>
    <select name="country" id="country">
    <option value=""> -- please choose -- </option>
    <option value="ie">Ireland</option>
    <option value="uk">Great Britain</option>
    </select>
    </tr>
    <tr>
    <th>Cities</th>
    <td id="cities">please choose a country first</td>
</tr>
    </table>
   <script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>


<script type="text/javascript">
    $(document).ready(setup_country_change);
        function setup_country_change(){
            $('#country').change(update_cities);
        }
        function update_cities(){
            var country=$('#country').attr('value');
            $.get('phpjquerybook/get_cities/'+country, show_cities);
        }
        function show_cities(res){
            $('#cities').html(res);
        }       
        </script>


</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:36:43+00:00Added an answer on May 13, 2026 at 9:36 am

    To get the third parameter in a method of a controller you can easily use the parameters of the method to get these, or the uri class to get the segments. In the first case you would use

    function get_cities($country = null){
    
        switch($country){
    
        ....
    

    see codeigniter userguide for passing uri parameters to controllers and uri library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 269k
  • Answers 269k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Apperently you can't. From the first answer on the linked… May 13, 2026 at 1:12 pm
  • Editorial Team
    Editorial Team added an answer It’s very important to know what can cause an application… May 13, 2026 at 1:12 pm
  • Editorial Team
    Editorial Team added an answer Assertions should be used for expressing invariants, or preconditions. In… May 13, 2026 at 1:12 pm

Related Questions

I am trying to implement some sort of MVC in Java. Actually it's more
I am using Single-Table Inheritance (STI) on one of my models for a Rails
I am working on the admin section of a new rails app and i'm
I am new to rails so sorry for the simple question. I have followed
i'm new to ruby on rails and am working with version 2.3 on mac

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.