It will only autofocus with camera's that have build-in AF-motors, the D40 and D60 have none. Don't worry though. I have the same lens on the D40, it works good when photographing stationary objects With action.. It's a different story..
You could certainly look into the AF-s 35mm f/1.8G. That's probably better suited as a normal for your D40. It's not that much more, either (than the 50mm f/1.8D).