I'm trying to learn javascript at the moment, but I can't figure out why the below code doesn't work. The page has a textbox you can't type in by using onfocus="blur()", then click the button to make onfocus="focus()" so you can type in it, then click again to change it back to onfocus="blur()". But it doesn't work. Can anyone tell me what I've done wrong?
Thanks
- Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
var i=0;
function typejim()
{
if (i==0)
{
window.document.form1.textbox1.onfocus="focus()";
window.document.form1.textbox1.value="You can type in me";
window.document.form1.typebutton.value="Cancel";
i++;
}
else if (i==1)
{
window.document.form1.textbox1.onfocus="blur()";
window.document.form1.textbox1.value="you can't type in me!";
window.document.form1.typebutton.value="type";
i--;
}
}
</script>
</head>
<body>
<form name="form1">
<input type="text" name="textbox1" value="you can't type in me!" onfocus="blur()">
<input type="button" value="type" name="typebutton" onclick="typejim()">
</form>
</body>
</html>