Dynamical response function in sodium and aluminum from time-dependent density-functional theory