title: Javascript for onblur event
body: <p>Building a registration form using webmatrix,asp.net &amp; Javascript,sql server CE. I'm writing an onblur event for the Username textbox.When focus leaves the textbox, it checks if there is an exisiting username in database and displays a label if yes.The foll. code is not working as js code is ignored if inside the "@{}" block. It works fine outside the "@{}" block but then i cant give a condition there.Please help me out.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script&gt;
  function RegUsernameLeave()
  {
    @{
       regusername=Request.Form["regusername"];
       if(!regusername.IsEmpty())
        {
          var db = Database.Open("myshop");
          int usercount = db.QueryValue("select count(*) from webusers where username=@0",regusername);
          db.Close();
          if(usercount!=0){
          document.getElementById("msg").innerHTML="Username already exists";}
        }
     }
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;label&gt;Username:&lt;/label&gt;
  &lt;p&gt;&lt;input type="text" id="regusername" onblur="RegUsernameLeave()"/&gt;
  &lt;label id="msg"&gt;&lt;/label&gt;&lt;/p&gt;
  &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>