I think that there are two possibilities I would check on. Either the cable of the digitizer is not completely snapped into its socket (that is, it got loose) or the digitizer is damaged and needs to be replaced. However, replacing the digitizer is not very difficult.
Here are my recommendations:
First: Open the iPhone and check if the rectangle connector of the digitizer got loose. It is the connector that is labeled with #2; this connector needs to lay even on its socket. For the right cable, see the guide on step 5: iPhone 3GS Display Replacement
If the connector is not loose, then...
Second: I would consider of replacing the digitizer. The good news is that the digitizer of the iPhone 3GS is not glued to the display. This means you can easily separate it from the display by removing the screws. Just follow the guide "Display" of the 3GS here on iFixit. Then order a new one (costs about $10).
I hope I could help you.