none
Drop down menu in settings

    Question

  • Hi all,

    I'm trying to create a simple settings file.  I just need a drop down menu that will open the previous selection upon opening the settings.  At the moment, when I re-open the settings, the first option in the drop drown menu is selected even if I select the 2nd or 3rd and hit "OK".

    Here's my HTML:
    <body onload="init()">
        <span id="collection" style="font-family: Arial; font-size: 10pt;">
            Collection:<br>
            <select id='library' onchange='changeLibrary(this);'>
       
                <option value="0">Perseus &amp; Furman</option>
                <option value="1">Perseus</option>
                <option value="2">Furman</option>
               
            </select>
            <p>Library</p>
        </span>
    </body>

    Here's my Javascript.
    function init() {
            var librarySelection = System.Gadget.Settings.read("librarySelection");
            if (librarySelection != "") library.selectedIndex = parseInt(librarySelection);
        }

        function changeLibrary(this) {
            searchLibrary = this.selectedIndex ;
        }

        System.Gadget.onSettingsClosing = SettingsClosing;
        function SettingsClosing(event)
        {
             if (event.closeAction == event.Action.commit) {
                 librarySelection = searchLibrary + "" ;
                System.Gadget.Settings.write("librarySelection", librarySelection);
            }
           
            event.cancel = false;
        }


    I wish I could trace the problem to something but I'm not sure how to debug a Gadget.

    Thanks,
    Seth
    Friday, March 09, 2007 9:55 PM

All replies

  • You're not assigning the value correctly.  As you're code stands you'll also have a problem storing '0' as a setting.  Change init() as below and it should work:

    function init() {
    var librarySelection = System.Gadget.Settings.readString("librarySelection");
    if (librarySelection != "") library.value = librarySelection;
    }

    Saturday, March 10, 2007 11:03 AM
  • The problem was actually a Javascript scope issue.  I did apply your code though, Jonathan.  Thanks for the help.

    Seth
    Sunday, March 11, 2007 8:47 PM