Not pretty, but shows you what to do:
Code:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
Enter grams of fat:
<input type="text" id="fatin" onkeyup="document.getElementById('fat').value = document.getElementById('fatin').value/300;">
This is a changed fat thing: <input id="fat"><br />
Enter grams of sugar:
<input type="text" id="sugin" onkeyup="document.getElementById('sugar').value = document.getElementById('sugin').value/4;">
This is a changed sugar thing: <input id="sugar">
</body>
</html>
Did not check for numbers only.