title: Looping through a ASP.NET Listbox with Javascript not working
body: <p>I'm trying to loop through an ASP.NET listbox with Javascript, but I'm getting a null object or undefined when it hits the lboxRight variable in the for loop. Here's what I have.</p>
  
  <pre><code>function save() {
    var containsTypeA = false;
    var containsTypeB = false;
    var containsType = false;
    var lboxRight = $get('&lt;%=lboxRight.ClientID %&gt;').value;
  
    if (lboxRight != null) {
      for (var i = 0; i &lt; lboxRight.options.length; ++i) {
        if (lboxRight.options[i].value == "Type A") {
          containsTypeA = true;
        }
        if (lboxRight.options[i].value == "Type B") {
           containsTybeB = true;
        }
      }
      containsType = true;
    }
  }
  </code></pre>
  
  <p>There's an onclick event mapped to when the save button is pressed that calls this function. Am I doing this the right way to look at the listbox and tell me if it has this specific value in it? My intention is for the listbox to contain <code>Type A</code> as a value and then when it loops through the listbox, if it finds that value within the list it will set that variable to true for some other logic. Visual Studio seems to complain about the for loop line, what am I doing wrong here? I am using the exact same loop written elsewhere and it works fine, so I am not understanding why this one isn't working. </p>
  
  <p>Is there anything wrong with this as I have written it?</p>