You can't consider Afghanistan and Iraq (selling weapons to them) as anything else than a strategic move that backfired.
I don't think they backfired at all -- both wars accomplished exactly what the United States wanted, stopping the creation of another Soviet satellite and proving to Iran that we were willing to oppose it over its public support for terrorism.
Claiming they "backfired" is like saying the United States didn't win World War II because five years later the aggressor Soviet airforce was still flying the P-39s we sold them to fight Hitler. The two things are completely separate in everyones mind, just as a very succesful foreign policy pursued in the 1980s is wholly separate from events twenty years later.
But this I say from the outside. A similar situation is the dirty war, which had US support. Those who suffered it can't think much of US government for supporting that hell.
Well, it's a nice thought, but you're putting the cart before the horse -- the United States fought the Soviets and the Iranians in reaction to the fact that these groups *already* had it in for the United States.
Afghanistan and the Iran-Iraq war aren't situations where the United States decided to go piss off some friendly country for no reason -- they were cases where the country was reacting to the actions of countries that were already enemies. You're not ever going to win back the hearts and minds of the guys blowing up your airliners and trying to set up nuclear missile silos off your mainland coast... and you certainly can't blame the United States for opposing things like that in the first place. (Unless, of course, you're part of the internet, where all radical Stalinists and Muslim extremists are wholly blameless for their actions.)
Now here's a theory: the US supported the taliban but, unlike what happened with the dirty war, later realized their mistake (they weren't all good and were unleashing hell on the local people - which, for what I hear, is true). So, not only it retired its support, but started fighting it and trying to overthrow this Taliban government. I guess they felt guilty. Am I close?
Not really. I'd like to live in a country that would be willing to kick the crap out of foreign powers just because they have terrible governments -- but the United States doesn't do that. Invading Afghanistan was directly a response to the September 11th tacks, nothing more and nothing less.
And when you say the US "supported the Taliban", you're hitting a very vauge mark -- we're not talking about the US agreeing with their policies (which became radicalized long after the United States was involved in their war with Russia)... we're talking about the US providing logistical support to Afghanistan for a very brief period during their war with a much, much more threatening enemy.
The internet at large gets stupid confused about this - the United States didn't go around saying the Taliban was okay, ever. It gave the government of Afghanistan weapons to fight off the Russians -- just like the Russians did to the North Koreans and the North Vietnamese. No implied support for any of these groups morals ever... it's just how the cold war was fought. (THe claim also tacitly suggests that the US must have *always* supported the Taliban -- no, the US had opposed them for many, many, many, many years after seeing how they ran their country.)