开发者

JQuery Cascade plugin to remember last selected state

I'm using the JQuery cascade plugin (here)

I have it so I can select a book section in the first dropdown, which populates with chapters in the second drop down. e.g:

var list1 = [
            {'When':'0','Value':'0','Text':'Chapter 1'},
            {'When':'0','Value':'1','Text':'Chapter 2'},
            {'When':'0','Value':'2','Text':'Chapter 3'},
                            ...(snip..)

            {'When':'1','Value':'0','Text':'Appendix 1'},
            {'When':'1','Value':'1','Text':'Appendix 2'},
            {'When':'1','Value':'2','Text':'Appendix 3'},
                            ....(snip..)
];

function commonTemplate(item){
   return "<option value='" + item.Value + "'>" + item.Text + "</option>";
}; 
function commonTemplate2(item) {
            return "<option value='" + item.Value + "'>***" + item.Text + "***</option>"; 
        };
        
        function commonMatch(selectedValue) {
            return this.When == selectedValue; 
        };

Which is then called by:

jQuery(document).ready(function()
    {   
        jQuery("#section").cascade("#chapter",{                 
            list: list1,            
            template: commonTemplate,
            match: commonMatch          
        });
    });

my form is pre-populated with section0 and it's associated chapters. Everything works fine - when I select book 2, the script fires and populates the second drop down with the chapters from book 2 etc.

My problem is: When I select a book like "Section 2, Chapter 3", I would like that book and chapter to load while the form on the page displays "Section 2, Chapter 3". This way the user can quickly go to chapter 4 or whatever. Currently, when Section 2, Chapter 3 loads, the form defaults to "Section 1, Chapter 1" which is the default form value from the first time the user arrived at the page.

My Question is: How can I have a default value the first time, but when a user submits the form, the page reloads remembering the开发者_开发百科 last selected section/chapter in the form?

Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜