In Juan Carlos case, it's difficult to say he was "elected".
I would say he was "appointed" by Franco.
Franco toyed with some other candidates, but at the end of the day, they never had a chance.
Franco was a true monarchic and wanted to restore the Borbonic dynasty. He just could not pass it to the rightful heir, the CoB, as he disagreed with his political beliefs and he thought he could model JC, a young and unprepared prince, at his own image.
The Belgians elected a son of Louis-Philippe to the throne but his election was unacceptable to some of the powers so they went for Leopold of Saxe-Coburg-Coburg-Gotha.
In late 1813 the Dutch elected prince William VI of Orange as their sovereign ruler. The Congress of Vienna elevated him to King of the Netherlands.
The Swedish parliament elected to appoint Jean-Baptiste Bernadotte as crown prince.
The later Christian IX was chosen to succeed the senior line of Danish kings when that line was about to end.
Franco elected Juan Carlos as his successor while his father the count of Barcelona was still alive as were descendants of the count's older brother.
In 1688/1689 the Parliaments of England and Scotland elected to the throne the oldest daughter and son-in-law/nephew of James II/VII as monarchs. Later it chose to exclude all Catholics to the line of succession thus opting for a German protestant to succeed rather than a British born Stuart.
Most monarchies -- at least in the ancient world -- started off elective. They largely evolved into hereditary institutions by default. If you examine the earliest days of any dynasty before 1500, you'll notice that oftentimes the succession was not clear. Look at England after the Normandy invasion, for one ...