Skip to content

Instantly share code, notes, and snippets.

@williame
Created April 2, 2012 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williame/2282116 to your computer and use it in GitHub Desktop.
Save williame/2282116 to your computer and use it in GitHub Desktop.
<html>
<head>
<script type="text/javascript">
<!--
function onkey(event) {
if(event.target.id == "b") {
var c = document.getElementById("c");
if(!c) {
document.getElementById("a").innerHTML += "<br/><input id=\"c\" type=\"text\"/>";
c = document.getElementById("c");
document.getElementById("status").textContent = "created c "+c
} else {
document.getElementById("status").textContent = "activing c "+c;
}
c.onkeydown = onkey;
c.focus();
} else {
document.getElementById("status").textContent = "activing b";
document.getElementById("b").focus();
}
}
function test() {
var b = document.getElementById("b");
b.onkeydown = onkey;
b.focus();
}
//-->
</script>
<body onload="test();">
<noscript>
Sorry, you need javascript. Not much to see here otherwise; move along.
</noscript>
<div id="status"></div>
<div id="a">
<input id="b" type="text"/>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment