calling auto complete source not working

calling auto complete source not working

I have 2 radio button. 1) rdoWindows 2) rdoUnix
i want to the autocomplete source to load only when rdoWindows checked. With this code the auto complete source loading even when rdoUnix is checked. Why is that?

  1. <script type="text/javascript">
  2.     $(document).ready(
  3.       function () {
  4.           
  5.           $('#HostName').keypress(

  6.       
  7.            function () {
  8.               var value = document.getElementById('HostName').value;
  9.               if ($('#HostName[document_type]').val() != '') {
  10.                   if ($("#rdoWindows").is(":checked"))
  11.                    {
  12.                       $('#HostName').autocomplete(
  13.                      {
  14.                          source: '/Inventory/WebService/ServerHandler.ashx'
  15.                      });
  16.                   }
  17.                   //alert(value);
  18.               }
  19.           }); // HostName

  20.       
  21.       })

  22. </script>