title: Can not make the settings from the sidebar gadget get applied
body: <p>OK, I am not an expert at Sidebar Gadgets, but I have this project I will have to make for school. Have tried to solve it on my own but I got really stuck.</p>
  
  <p>I will have to use the Cirip API (Cirip.ro being a kind of Twitter), and for the use of the API I have to input the username. I do so by means of the Settings, but when closing the settings there is no effect. </p>
  
  <p>Here is the code, but it's pretty messy. I am not a web programmer so javascript/html is new to me.</p>
  
  <p><a href="http://www.box.net/shared/7yogevhzrr" rel="nofollow">http://www.box.net/shared/7yogevhzrr</a></p>
  
  <hr/>
  
  <p><strong>EDIT:</strong> Ok, so I have narrowed it down a little and optimized my code here but it is still not working. I have made it as simple as possible. </p>
  
  <p><strong>In the main html I have this:</strong></p>
  
  <pre><code>&lt;script language="javascript"&gt;
      document.write(getUserName());
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>In the gadget.js:</strong></p>
  
  <pre><code>var userName;
  
  document.onreadystatechange = function DoInit() {
  
      document.body.style.width = 251;
      document.body.style.height= 351;
      document.body.style.margin=2;
      userName="danieliuhasz";
      System.Gadget.settingsUI = "settings.html";
      System.Gadget.onSettingsClosing = settingsClosed;
  
  }
  
  function setUserName(userNameSet){
  
      userName = userNameSet;
  }
  
  function getUserName(){
  
      return userName;
  }
  
  function settingsClosed()
  {
  
      var username = System.Gadget.Settings.read("username");
      setUserName(username);
  }
  </code></pre>
  
  <p><strong>In the settings.html:</strong></p>
  
  <pre><code>&lt;body&gt;
  
  Username:&lt;br /&gt;
  &lt;input name="userBox" type="text" maxlength="50" /&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p><strong>In settings.js:</strong></p>
  
  <pre><code>document.onreadystatechange = function DoInit()
  {    
  
      if(document.readyState=="complete")
      {
          var user = System.Gadget.Settings.read("userName");
  
          if(user != "")
          {
              userBox.value = user;
          }       
      }        
  }
  
  
  System.Gadget.onSettingsClosing = function(event)
  {
  
      if (event.closeAction == event.Action.commit)
      {
          var username = userBox.value;
          if(username != "")
          {
                System.Gadget.Settings.write("username", username);
                System.Gadget.document.parentWindow.settingsClosed();
  
          }
      }
  }
  </code></pre>
  
  <p>I really can't figure it out. The output of this is "undefined".</p>