title: IE6 displays JavaScript error for below given function and error is also mentioned below
body: <p>I have a function </p>
  
  <pre><code>function setbid(catid)
  {
  if(catid == 30)
  {
  
  document.getElementById('bannerid').value = 1;
  
  }
  else if(catid == 31){
  document.getElementById('bannerid').value = 2;
  }
  else if(catid == 32){
  document.getElementById('bannerid').value = 6;
  }
  }
  </code></pre>
  
  <p>this function is being called onchange event of select box.</p>
  
  <p>now when the value of select box is changed IE throws me an error saying </p>
  
  <p>"document.getElementId(....)" is null or not an object..</p>
  
  <p>Now what can i infer from this?</p>
  
  <p>please help..</p>
  
  <blockquote>
    <p><strong>UPDATE</strong></p>
  </blockquote>
  
  <p>As per David's Reply
  how can i check for its existance before the assignment of value to that field,? Also other browsers do not display this error, I have this bannerid field as hidden field in the document... What should be done?</p>
  
  <p>Below is the screen shot of the error displayed onchange of select box
  <img src="https://i.stack.imgur.com/cPSnv.jpg" alt="alt text"></p>
  
  <blockquote>
    <p><strong>Update 2</strong>
    Update as per the answer of @haylem</p>
  </blockquote>
  
  <pre><code>&lt;script&gt;
  function setbid(catid)
  {
  var lookup = {
      '30' : 1,
      '31' : 2,
      '32' : 6
    };
  
    if (lookup.hasOwnProperty(catid)) {
      var el = document.getElementById('bannerid');
  
      if (el) {
        el.value = lookup[catid];
      }
    }
  /*if(catid == 30)
  {
  if(typeof(document.getElementById('bannerid')) == null ){
  document.getElementById('bannerid').value = 1;
  }
  }
  else if(catid == 31){
  document.getElementById('bannerid').value = 2;
  }
  else if(catid == 32){
  document.getElementById('bannerid').value = 6;
  }*/
  }
  &lt;/script&gt;
  
  &lt;div style="margin:0px auto"&gt;
  &lt;div class="instantprice-popup-bg"&gt;
  &lt;form name="instantpop" id="instantpop" action="" method="post" style="margin:0px; padding:0px" onsubmit=""&gt;
      &lt;input type="hidden" name="sessid" id="sessid" value="&lt;?php echo $_GET['osCsid'];?&gt;"&gt;
  &lt;div class="instantprice"&gt;
  
              &lt;ul&gt;
                  &lt;li class="text12pt" style="color:#FF0000; display:none;" id="appsize"&gt;For special low price on sizes over 30ft. wide and 10ft. height contact us on sales@bannerbuzz.com.&lt;/li&gt;
                  &lt;li class="text12pt" style="color:#FF0000; display:none;" id="vinylsize"&gt;Please enter width upto 30 ft &amp; height upto 5 ft for Vinyl Signs/Decals(Posters).&lt;/li&gt;
  
                  &lt;li class="col1"&gt;Select Product&lt;/li&gt;
                  &lt;li class="col2"&gt;
  
                      &lt;input type="hidden" name="price" id="price" value="&lt;?php echo "15"; ?&gt;" /&gt;
                      &lt;input type="hidden" name="bannerid" id="bannerid" value="" /&gt;
                      &lt;select name="product" class="dropdownfield" id="product" style="width: 180px;" onchange="javascript:setbid(document.getElementById('product').value);"&gt;
                      &lt;option value=""&gt;Select Product&lt;/option&gt;
                      &lt;?php
                          while($result=mysql_fetch_object($sql_query))
                          {
                              ?&gt;&lt;option value="&lt;?php echo $result-&gt;categories_id;?&gt;" &lt;?php if($_POST['product'] == $result-&gt;categories_id) {?&gt; selected="selected" &lt;?php } ?&gt;&gt;&lt;?php echo $result-&gt;categories_name;?&gt;&lt;/option&gt;&lt;?php 
                          }
                      ?&gt;
                      &lt;/select&gt;
  
                  &lt;/li&gt;
                  &lt;li class="col1"&gt;Select Size (in ft.)&lt;/li&gt;
                  &lt;li class="col2"&gt;
                      &lt;div class="sizebox" style="width:250px;"&gt;
                          &lt;div class="sizebox col1"&gt;&lt;input name="size_w" id="size_w" type="text" class="sizetextfield1" value="&lt;?php if(isset($_REQUEST['size_w'])){ echo $_REQUEST['size_w']; } else { echo "2"; } ?&gt;" &gt;&lt;/div&gt;
                          &lt;div class="sizebox col2"&gt;&lt;img src="images/homepage/up-arrow.jpg" width="12" height="9" border="0" align="top" onclick="increaseCounter('size_w')" /&gt;&lt;img src="images/homepage/down-arrow.jpg" width="12" height="9" border="0" onclick="decreaseCounter('size_w');" /&gt;&lt;/div&gt;
                          &lt;div class="sizebox col3"  style="width:35px;"&gt;width&lt;/div&gt;
                          &lt;div class="sizebox col1"&gt;&lt;input name="size_h" id="size_h" type="text" class="sizetextfield1" value="&lt;?php if(isset($_REQUEST['size_h'])){ echo $_REQUEST['size_h']; } else { echo "2"; } ?&gt;" style="margin-left:8px" &gt;&lt;/div&gt;
                          &lt;div class="sizebox col2"&gt;&lt;img src="images/homepage/up-arrow.jpg" width="12" height="9" border="0" align="top" onclick="increaseCounter('size_h');" /&gt;&lt;img src="images/homepage/down-arrow.jpg" width="12" height="9" border="0" onclick="decreaseCounter('size_h');" /&gt;&lt;/div&gt;
                          &lt;div class="sizebox col3" style="width:35px;"&gt;&amp;nbsp;height&lt;/div&gt;
                          &lt;input name="size" id="size" type="hidden" value="&lt;?php echo $_REQUEST['size_h'].'x'.$_REQUEST['size_w']; ?&gt;"&gt;
                      &lt;/div&gt;
                  &lt;/li&gt;
                  &lt;li class="col1"&gt;Select Quantity&lt;/li&gt;
                  &lt;li class="col2"&gt;
                      &lt;select id="qty" name="qty" &gt;
                          &lt;?php 
                              for($i=1;$i&lt;=100;$i++)
                              {
                                  ?&gt; &lt;option value="&lt;?php echo $i;?&gt;" &lt;?php if($_POST['qty'] == $i) {?&gt; selected="selected" &lt;?php } ?&gt;&gt;&lt;?php echo $i;?&gt;&lt;/option&gt; &lt;?php
                              }
                          ?&gt;
                      &lt;/select&gt;
                  &lt;/li&gt;
                  &lt;li class="col1"&gt;Select Shipping&lt;/li&gt;
                  &lt;li class="col2"&gt;
                      &lt;select id="shipping_method" name="shipping_method" class="dropdownfield" &gt;
                          &lt;option value=""&gt;Select Shipping&lt;/option&gt;
                          &lt;option value="standard" &lt;?php if($_POST['shipping_method'] == 'standard') {?&gt; selected="selected" &lt;?php } ?&gt;&gt;Standard (7 - 12 days from proof)&lt;/option&gt;
                          &lt;option value="expedited"&lt;?php if($_POST['shipping_method'] == 'expedited') {?&gt; selected="selected" &lt;?php } ?&gt;&gt;Expedited (5 work days from Proof)&lt;/option&gt;
                      &lt;/select&gt;
                  &lt;/li&gt;
                  &lt;li class="col1" id="sidehead"&gt;Two Side Banner&lt;/li&gt;
                  &lt;li class="col2" id="sideval"&gt;
                      &lt;input type="checkbox" id="side" name="side" value="1"  /&gt;
                  &lt;/li&gt;
                  &lt;li class="col1"&gt;Product Price&lt;/li&gt;
                  &lt;li class="col2"&gt;&lt;span class="text15pt" id="total_display"&gt;$0&lt;/span&gt;
                      &lt;input type="hidden" id="total" name="total" class="textfield" value="15" readonly="readonly" style="width:60px;"/&gt;
                  &lt;/li&gt;
  
                  &lt;li class="col1"&gt;Shipping Cost&lt;/li&gt;
                  &lt;li class="col2"&gt;&lt;span class="text15pt" id="shipping_display"&gt;$0&lt;/span&gt;
                      &lt;input type="hidden" id="shipping" name="shipping" class="textfield" value="" readonly="readonly" style="width:60px;" /&gt;
                  &lt;/li&gt;
                  &lt;li class="bannerprice" id="grand_total_display"&gt;TOTAL PRICE : $0
  
                  &lt;/li&gt;&lt;input type="hidden" id="grand_total" name="grand_total" value="" readonly="readonly" style="width:60px;" /&gt;
                  &lt;li style="float:none; text-align:center"&gt;
  
                      &lt;input type="submit" class="getprice-btn" name="getprice" value="" /&gt;
  
                  &lt;/li&gt;
                  &lt;li class="text12pt"&gt;Final Price, No Hidden Charges&lt;/li&gt;
              &lt;/ul&gt;
              &lt;input type="hidden" name="getpriceclick" value="1" /&gt;
          &lt;/div&gt;
          &lt;/form&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>