Well, that’s weird. I decided that it must be something else on the page or in the code that was causing trouble, so I started again with a blank page and no code. After building the code and the page up again step by step, everything worked. There must have been something bad lurking in the background, though I have no idea where.
Thank you for your help, Yisrael.