2

Now I need a three level selected option, and the second selected option will change with first selected option's value,so I use the jquery plugin "select box manipulation" can do it, but now I use codeigniter, so I want to integrate it using libraries, how can do it?

How can I integrate jquery select box manipulation incodeigniter? Do I need to use a library, or are there other methods to do it?

Who can give me some point? http://www.texotela.co.uk/code/jquery/select/

4
  • Why do you need a (server-side) library for that? By a quick look at the link, you just need a regular controller to handle the ajax requests Commented Nov 26, 2011 at 14:45
  • Beacaue my three level selected option data is from mysql, and when i have default value, i want to show the value, but i can change the selectd option value too. Commented Nov 26, 2011 at 15:43
  • So what? Your controller manages the page with the options, and jQuery fires an Ajax request to another controller (or another method of the same) which in turns queries the model and echoes back the new options..Don't see the use of a library here. If you cleary say how's this "three level selected option" is strctured, and what you want it to do onchange, I can show you some code Commented Nov 26, 2011 at 16:10
  • I need your some advice,thx!! Commented Nov 26, 2011 at 16:29

1 Answer 1

1

No, you don't need a library. Just create methods in your controller to get data for your forms.

One idea would be to return the respective form field to the request to be populated in a div or something.

View:

<select name="shirts" onchange="getField(this.value)">
<option value="small">Small Shirt</option>
<option value="med">Medium Shirt</option>
<option value="large" selected="selected">Large Shirt</option>
<option value="xlarge">Extra Large Shirt</option>
</select>
<div id="field2"></div>

Javascript:

function getField(val){
    $.ajax({
        type:"get",
        url: "/controller/getField/"+val,
        success: function(data){
            $('#field2').html(data);
        }
    });
}

Controller:

...
public function getField($val=''){
    switch($val){
       case 'small':
       //$options = get data and do stuff; 
       echo form_dropdown('shirts', $options, 'large');
       break;
    }
}

http://codeigniter.com/user_guide/helpers/form_helper.html
http://api.jquery.com/jQuery.ajax/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.