<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<script type="text/javascript" language="javascript">
function runFunction(e){
var keyPressed = (window.event ? event.keyCode : e.which); // Set up values so that we use the right
var srcObject = (window.event ? event.srcElement : e.target); // terminology for IE and FireFox
if(keyPressed == 13){ //Enter Key
var value = parseInt(srcObject.value);
if(!isNaN(value)){ //Making sure a number was entered
// Perform some Math function on the value
alert("The square root of " + value + " is " + Math.sqrt(value));
}
else {
alert("I'm sorry but '" + srcObject.value + "' is not a number in this universe.");
}
//Clear the input field
srcObject.value = "";
//Put the cursor back in the input field
srcObject.focus();
}
}
</script>
</head>
<body>
<label for="inputfield">Enter A Number and Press 'Enter': </label>
<input type="text" name="inputField" id="inputField" onkeypress="runFunction(event);" />
</body>
</html>