I am having trouble with some javascript code that checks the first 2 letters of what the user inputs and whether it equals a certain set of characters.

If the user for instance types in 'TT' in an input field, then i want the holding div to disappear, if anything else is typed in then this action wont happen. My code is below:

<script type="text/javascript">
function checkCode() {
	var x=document.forms["myform"]["code"].value.substring(0, 2);
	if (x == 'TT')
		document.getElementById('main').style.display = 'none';

<div id="main">
<form name="myform" action="check-form.php" method="post">
    <table id="table" cellpadding="0" cellspacing="0">
        <td><input id="code" type="text" name="code" onkeyup="checkCode()" onchange="checkCode()" /></td><td><input type="submit" value="SEND"/></td>
I believe the problem lies in the javascript line: "if (x == 'TT')", as the rest of the script responds but it just doesnt recognise whether 'x' starts with 'TT'

Any help would be greatly appreciated